门户docker化部署
# 背景
得快速部署现有巡检系统,交付客户使用;
# 基本环境
yum -y install unzip
yum -y install wget
yum -y install gcc gcc-c++ autoconf make
yum -y install openssl-devel
2
3
4
httpd服务
yum install yum-utils createrepo httpd
which httpd
systemctl httpd
systemctl start httpd
systemctl enable httpd
vi /etc/httpd/conf/httpd.conf
systemctl restart httpd
#查找软件
which httpd
find / -name httpd
2
3
4
5
6
7
8
9
10
11
时间同步
which ntp
yum -y install ntp
systemctl restart ntpd
systemctl enable ntpd
systemctl stop ntpd
systemctl start ntpd
vi /etc/ntp.conf
ntpstat
ntpq -p
date
ntpdate vhost-118-21
2
3
4
5
6
7
8
9
10
11
12
13
# 干净离线虚拟环境部署
# nginx/redis/mysql安装
# nginx
源码安装
# install nginx
RUN cd $WORKDIR/soft/nginx \
&& tar -zxvf nginx-1.18.0.tar.gz \
&& cd nginx-1.18.0 && ./configure --prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
&& make && make install\
&& ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx \
&& rm -rf ../*.gz \
&& cp -rf $WORKDIR/soft/nginx/nginx.conf /usr/local/nginx/conf/
2
3
4
5
6
7
8
9
10
11
12
/usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log /var/log/nginx/error.log warn;
#pid logs/nginx.pid;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
client_max_body_size 500m;
#gzip on;
include /usr/local/nginx/conf/conf.d/*.conf;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/usr/local/nginx/conf/conf.d/autorun.conf
server {
listen 9001;
server_name localhost;
large_client_header_buffers 4 16k; #header大小
client_max_body_size 300m; #上传文件大小限制
client_body_buffer_size 128k; #缓冲区大小
proxy_connect_timeout 600; #设置与upstream server的连接超时时间
proxy_read_timeout 600; #设置与代理服务器的读超时时间
proxy_send_timeout 600; #发送请求给upstream服务器的超时时间
underscores_in_headers on; #header允许使用带'_'的参数
#注意这个设置防止docker环境下,刷新端口没有的问题;
absolute_redirect off;
# 统一门户前端
location / {
root /root/app/AAWeb/AAPortal;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location ^~ /modules {
root /root/app/AAWeb;
}
location /aiFactoryServer {
proxy_pass http://127.0.0.1:9005/aiFactoryServer;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#巡检工具本地测试
location /autorunweb {
proxy_pass http://127.0.0.1:8082/autorunweb;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#实时引擎
location /ZRealTEng {
proxy_pass http://127.0.0.1:8089/ZRealTEng;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
简化为一个配置,nginx.conf
,并优化端口调整问题;
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
# error_log logs/error.log info;
error_log /var/log/nginx/error.log warn;
# pid logs/nginx.pid;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# access_log logs/access.log main;
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
client_max_body_size 500m;
#include /usr/local/nginx/conf/conf.d/*.conf;
server {
listen 80;
server_name localhost;
large_client_header_buffers 4 16k; #header大小
client_max_body_size 300m; #上传文件大小限制
client_body_buffer_size 128k; #缓冲区大小
proxy_connect_timeout 600; #设置与upstream server的连接超时时间
proxy_read_timeout 600; #设置与代理服务器的读超时时间
proxy_send_timeout 600; #发送请求给upstream服务器的超时时间
underscores_in_headers on; #header允许使用带'_'的参数
#proxy_set_header X-Forwarded-Host $host;
#proxy_set_header X-Forwarded-Server $host;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header Host $host:$server_port; #这里是重点,这样配置才不会丢失端口
absolute_redirect off;
# 统一门户前端
location / {
root /srv/app/portal/AAWeb;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#location ^~ /modules {
# root /srv/app/portal/AAWeb;
#}
location /aiFactoryServer {
proxy_pass http://127.0.0.1:9005/aiFactoryServer;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#巡检工具本地测试
location /autorunweb {
proxy_pass http://127.0.0.1:8082/autorunweb;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#实时引擎
location /ZRealTEng {
proxy_pass http://127.0.0.1:8089/ZRealTEng;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
安全部分优化处理:
# API接口的路径不允许给外部开放
location /aiFactoryServer/api/ {
deny all;
access_log off;
log_not_found off;
}
location /logos {
root /home/bdpcloud/portal/GSMAppWeb/daweb/;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
2
3
4
5
6
7
8
9
10
11
有前缀部分优化处理:
前端配置:
# base指定页面路由的前缀,比如/bdpPortal,默认值:/
# https://umijs.org/zh/config/#base
base=/daweb
# publicPath指定静态资源的前缀,比如/bdpPortal,默认值:/
# 这个参数跟base的区别是:base是指定路由,publicPath是针对html、css、js、img、svg等静态资源的前缀
# https://umijs.org/zh/config/#publicpath
publicPath=/daweb/
2
3
4
5
6
7
8
9
源码路径在:
/srv/app/portal/AAWeb/daweb下面;
location /daweb {
root /srv/app/portal/AAWeb/;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#location ^~ /modules {
# root /srv/app/portal/AAWeb;
#}
location /daweb/aiFactoryServer {
proxy_pass http://127.0.0.1:9005/aiFactoryServer;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /daweb/autorunweb {
proxy_pass http://127.0.0.1:8082/autorunweb;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
初始化启动
# netstat -antlp
echo "启动nginx..."
nginx -g "daemon off;"
2
3
# redis
源码安装
# install redis
RUN cd $WORKDIR/soft/redis \
&& tar -zxvf redis-3.2.11.tar.gz \
&& cd redis-3.2.11 && make install PREFIX=/usr/local/redis \
&& ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli \
&& ln -s /usr/local/redis/bin/redis-server /usr/bin/redis \
&& rm -rf ../redis-3.2* \
&& cp -rf $WORKDIR/soft/redis/redis.conf /usr/local/redis/
2
3
4
5
6
7
8
初始化启动
echo "启动redis..."
redis /usr/local/redis/redis.conf
2
# mysql
源码安装
RUN yum -y install yum-utils make gcc-c++ libtool zlib zlib-devel unzip zip gettext pcre pcre-devel openssl openssl-devel wget \
&& yum -y install openssh-server openssh-clients \
&& yum -y install libaio net-tools numactl\
&& yum clean all
ENV LANG en_US.UTF-8
# install mysql
# RUN yum install -y libaio net-tools numactl
RUN useradd -s /sbin/nologin mysql \
&& mkdir -p /var/lib/mysql/data \
&& chown -R root /var/lib/mysql \
&& chown -R mysql:mysql /var/lib/mysql \
&& chown -R mysql /var/lib/mysql/data
RUN cd $WORKDIR/soft/mysql \
&& tar -zxvf mysql-5.7.35.tar.gz \
&& cd mysql-5.7.35 \
&& rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm \
&& rm -rf ../mysql-5.7* \
&& cp -rf $WORKDIR/soft/mysql/my.cnf /etc/my.cnf
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
初始化启动
# start mysql and init sql
rm -rf /var/lib/mysql/* && mysqld --initialize --user=mysql --basedir=/var/lib/mysql
mysqld --defaults-file=/etc/my.cnf --user root --skip-grant-tables &
sleep 10
mysql -uroot mysql </srv/app/soft/mysql/setpwd.sql
ps -ef | grep mysqld | grep -v grep | awk '{print "kill -9",$2}' | sh
echo "启动mysqld..."
mysqld --defaults-file=/etc/my.cnf --user root &
sleep 10
mysql -uroot -p$ROOT_PWD --connect-expired-password mysql </srv/app/soft/mysql/init.sql
echo "初始化数据库..."
mysql -uroot -p$MYSQL_PWD -e "
CREATE DATABASE IF NOT EXISTS dataportal DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE DATABASE IF NOT EXISTS autorun DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
quit
"
echo "导入门户数据..."
mysql -uroot -p$MYSQL_PWD dataportal </srv/app/portal/dataportal.sql
echo "导入巡检后端数据..."
mysql -uroot -p$MYSQL_PWD autorun </srv/app/autorun/autorun.sql
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# sshd
源码安装
&& yum -y install openssh-server openssh-clients \
初始化启动
echo "容器init初始化模式..."
# 默认容器密码
echo "root:${ROOT_PWD}" | chpasswd
#start sshd
ssh-keygen -A
#免密码本机跳本机
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
echo "启动sshd..."
/usr/sbin/sshd -D &
2
3
4
5
6
7
8
9
10
11
# JDK
源码安装
# install jdk
RUN cd $WORKDIR/soft/jdk \
&& tar -zxvf jdk-8u241-linux-x64.tar.gz \
&& mv jdk1.8.0_241/ /usr/local/java/ \
&& rm -rf *.gz
2
3
4
5
初始化启动
ENV JAVA_HOME=/usr/local/java
ENV JRE_HOME=/usr/local/java/jre
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH=$PATH:$JAVA_HOME/bin
2
3
4
mkdir -p /usr/lib/jvm/
ln -s /usr/local/java /usr/lib/jvm/jdk1.8.0_241
2
# jar部署
config
Redis,mysql,eureka地址;
license按照127.0.0.1重新修改;
# docker化部署
# README
# 构建
- 默认不使用缓存构建
sh build.sh
; - 使用缓存构建
sh build.sh -c true
- 构建后并发布
sh build.sh -p true
- 同时设置缓存和发布
sh build.sh -c true -p true
# 启动
- 默认不使用缓存启动
sh start.sh
; - 使用干净重置启动
sh start.sh true
# 不用脚本方式启动
docker run -d \
-p 28080:80 -p 26379:6379 -p 23306:3306 \
-v /data/autorun/mysql/log:/var/log/mysql \
-v /data/autorun/mysql/data:/var/lib/mysql \
--name autorun-pro autorun-pro
# docker exec -it autorun-pro bash
# curl localhost
2
3
4
5
6
7
8
# 完全跑通脚本
Dockerfile
使用本地资源;
FROM centos:centos7
LABEL author=samyzh version=0.0.1
RUN yum -y install yum-utils make gcc-c++ libtool zlib zlib-devel unzip zip gettext pcre pcre-devel openssl openssl-devel wget
ENV LANG en_US.UTF-8
# RUN unalias cp mv rm
WORKDIR /srv/app
COPY . .
# install nginx
RUN cd /srv/app/soft/nginx \
&& tar -zxvf nginx-1.18.0.tar.gz \
&& cd nginx-1.18.0 && ./configure --prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
&& make && make install\
&& ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
RUN unzip -d /srv/app/portal/ /srv/app/portal/AAWeb.zip
RUN cp -rf /srv/app/soft/nginx/nginx.conf /usr/local/nginx/conf/
# RUN nginx
# RUN rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm \
# && yum -y install nginx
# RUN cp -rf /srv/app/soft/nginx/nginx.conf /etc/nginx/nginx.conf
# install redis
RUN cd /srv/app/soft/redis \
&& tar -zxvf redis-3.2.11.tar.gz \
&& cd redis-3.2.11 && make install PREFIX=/usr/local/redis \
&& ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli \
&& ln -s /usr/local/redis/bin/redis-server /usr/bin/redis
RUN cp -rf /srv/app/soft/redis/redis.conf /usr/local/redis/
# RUN redis /usr/local/redis/redis.conf
# RUN yum install -y gcc epel-release redis
# RUN cp -rf /srv/app/soft/redis/redis.conf /etc/redis.conf
# install mysql
RUN yum install -y libaio net-tools numactl
RUN useradd -s /sbin/nologin mysql \
&& mkdir -p /var/lib/mysql/data \
&& chown -R root /var/lib/mysql \
&& chown -R mysql:mysql /var/lib/mysql \
&& chown -R mysql /var/lib/mysql/data
RUN cd /srv/app/soft/mysql \
&& tar -zxvf mysql-5.7.35.tar.gz \
&& cd mysql-5.7.35 \
&& rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm
RUN cp -rf /srv/app/soft/mysql/my.cnf /etc/my.cnf
# 这个配置在线安装太慢了;
# RUN rpm -Uvh https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm \
# && yum -y install mysql-community-server
# RUN cp -rf /srv/app/soft/mysql/my.cnf /etc/my.cnf
# install jdk
RUN cd /srv/app/soft/jdk \
&& tar -zxvf jdk-8u241-linux-x64.tar.gz \
&& mv jdk1.8.0_241/ /usr/local/java/
# RUN echo
ENV JAVA_HOME=/usr/local/java
ENV JRE_HOME=/usr/local/java/jre
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH=$PATH:$JAVA_HOME/bin
# pro
RUN unzip -d /srv/app/portal/ /srv/app/portal/eureka.zip
RUN unzip -d /srv/app/portal/ /srv/app/portal/GSMAppService.zip
# RUN unzip -d /srv/app/autorun/ /srv/app/portal/autorun.zip
EXPOSE 80
EXPOSE 6379
EXPOSE 3306
ENTRYPOINT ["/bin/bash", "./entrypoint.sh"]
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
entrypoint.sh
#!/bin/bash
redis /usr/local/redis/redis.conf
#nginx -c /usr/local/nginx/conf/nginx.conf
# start mysql and init sql
rm -rf /var/lib/mysql/* \
&& mysqld --initialize --user=mysql --basedir=/var/lib/mysql
mysqld --defaults-file=/etc/my.cnf --user root --skip-grant-tables &
sleep 10
mysql -uroot mysql < /srv/app/soft/mysql/setpwd.sql
ps -ef|grep mysqld |grep -v grep | awk '{print "kill -9",$2}'|sh
mysqld --defaults-file=/etc/my.cnf --user root &
sleep 10
mysql -uroot -proot-1234 --connect-expired-password mysql < /srv/app/soft/mysql/init.sql
mysql -uroot -pPass-1234 mysql < /srv/app/soft/mysql/dataportal.sql
#start portal and autorun
cd /srv/app/portal/eureka && sh stop.sh && sh start.sh
sleep 5
cd /srv/app/portal/GSMAppService && sh stop.sh && sh start.sh
sleep 5
# cd /srv/app/portal/autorun && sh stop.sh && sh start.sh
# sleep 5
netstat -antlp
nginx -g "daemon off;"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 优化基镜像
源码安装的mysql,nginx, redis,jdk环境;
# Dockerfile
及优化后,资源在线化; 可以通过-e
参数动态替换URLBASE及WORKDIR;
FROM centos:centos7
LABEL author=samyzh version=0.0.1
RUN yum -y install yum-utils make gcc-c++ libtool zlib zlib-devel unzip zip gettext pcre pcre-devel openssl openssl-devel wget
ENV LANG en_US.UTF-8
ENV WORKDIR /srv/app
ENV URLBASE=http://10.45.xx.xx:58888/files/autorun/pro
WORKDIR $WORKDIR
# COPY . .
ADD entrypoint.sh $WORKDIR/
RUN mkdir -p $WORKDIR/soft/nginx && cd $WORKDIR/soft/nginx \
&& wget $URLBASE/soft/nginx/nginx-1.18.0.tar.gz \
&& wget $URLBASE/soft/nginx/nginx.conf \
&& mkdir -p $WORKDIR/soft/redis && cd $WORKDIR/soft/redis \
&& wget $URLBASE/soft/redis/redis-3.2.11.tar.gz \
&& wget $URLBASE/soft/redis/redis.conf \
&& mkdir -p $WORKDIR/soft/mysql && cd $WORKDIR/soft/mysql \
&& wget $URLBASE/soft/mysql/mysql-5.7.35.tar.gz \
&& wget $URLBASE/soft/mysql/my.cnf \
&& wget $URLBASE/soft/mysql/init.sql \
&& wget $URLBASE/soft/mysql/setpwd.sql \
&& mkdir -p $WORKDIR/soft/jdk && cd $WORKDIR/soft/jdk \
&& wget $URLBASE/soft/jdk/jdk-8u241-linux-x64.tar.gz
# install nginx
RUN cd /srv/app/soft/nginx \
&& tar -zxvf nginx-1.18.0.tar.gz \
&& cd nginx-1.18.0 && ./configure --prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
&& make && make install\
&& ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
RUN unzip -d /srv/app/portal/ /srv/app/portal/AAWeb.zip
RUN cp -rf /srv/app/soft/nginx/nginx.conf /usr/local/nginx/conf/
# install redis
RUN cd /srv/app/soft/redis \
&& tar -zxvf redis-3.2.11.tar.gz \
&& cd redis-3.2.11 && make install PREFIX=/usr/local/redis \
&& ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli \
&& ln -s /usr/local/redis/bin/redis-server /usr/bin/redis
RUN cp -rf /srv/app/soft/redis/redis.conf /usr/local/redis/
# install mysql
RUN yum install -y libaio net-tools numactl
RUN useradd -s /sbin/nologin mysql \
&& mkdir -p /var/lib/mysql/data \
&& chown -R root /var/lib/mysql \
&& chown -R mysql:mysql /var/lib/mysql \
&& chown -R mysql /var/lib/mysql/data
RUN cd /srv/app/soft/mysql \
&& tar -zxvf mysql-5.7.35.tar.gz \
&& cd mysql-5.7.35 \
&& rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm
RUN cp -rf /srv/app/soft/mysql/my.cnf /etc/my.cnf
# install jdk
RUN cd /srv/app/soft/jdk \
&& tar -zxvf jdk-8u241-linux-x64.tar.gz \
&& mv jdk1.8.0_241/ /usr/local/java/
ENV JAVA_HOME=/usr/local/java
ENV JRE_HOME=/usr/local/java/jre
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH=$PATH:$JAVA_HOME/bin
EXPOSE 80
EXPOSE 6379
EXPOSE 3306
ENTRYPOINT ["/bin/bash", "./entrypoint.sh"]
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# entrypoint.sh
#!/bin/bash
nginx -g "daemon off;"
redis /usr/local/redis/redis.conf
# start mysql and init sql
rm -rf /var/lib/mysql/* \
&& mysqld --initialize --user=mysql --basedir=/var/lib/mysql
mysqld --defaults-file=/etc/my.cnf --user root &
sleep 10
mysql -uroot mysql < /srv/app/soft/mysql/setpwd.sql
ps -ef|grep mysqld |grep -v grep | awk '{print "kill -9",$2}'|sh
sed -i "s/\(skip-grant-tables\).*/#skip-grant-tables/" /etc/my.cnf
mysqld --defaults-file=/etc/my.cnf --user root &
sleep 10
mysql -uroot -prooxxx --connect-expired-password mysql < /srv/app/soft/mysql/init.sql
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
优化后:默认不设置跳过密码处理;启动时设置;
redis /usr/local/redis/redis.conf
# nginx -c /usr/local/nginx/conf/nginx.conf
# start mysql and init sql
rm -rf /var/lib/mysql/* \
&& mysqld --initialize --user=mysql --basedir=/var/lib/mysql
mysqld --defaults-file=/etc/my.cnf --user root --skip-grant-tables &
sleep 10
mysql -uroot mysql < /srv/app/soft/mysql/setpwd.sql
ps -ef|grep mysqld |grep -v grep | awk '{print "kill -9",$2}'|sh
mysqld --defaults-file=/etc/my.cnf --user root &
sleep 10
mysql -uroot -pxx --connect-expired-password mysql < /srv/app/soft/mysql/init.sql
#初始化项目sql
echo "初始化数据库..."
mysql -uroot -pPxxx -e "
CREATE DATABASE IF NOT EXISTS dataportal DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE DATABASE IF NOT EXISTS autorun DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
quit
"
echo "导入门户数据..."
mysql -uroot -pPxxx dataportal < /srv/app/portal/dataportal.sql
echo "导入巡检后端数据..."
mysql -uroot -pPxxx autorun < /srv/app/autorun/autorun.sql
# netstat -antlp
nginx -g "daemon off;"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
build.sh
#!/bin/bash
docker build -t centos7-nginx1.18-redis3.2-mysql5.7-jdk1.8 .
2
# 构建优化
# 构建脚本build.sh
是否使用cache
; sh build.sh ture
#!/bin/bash
###
# @Author: samy
# @email: yessz#foxmail.com
# @time: 2022-02-12 13:21:47
# @modAuthor: samy
# @modTime: 2022-03-01 16:02:23
# @desc: 构建镜像
# Copyright © 2015~2022 BDP FE
###
PRO_NAME=autorun-pro
PRO_VERSION=0.1.0
isCache=false
if [ $1 ]; then
isCache=$1
fi
if [ $isCache == true ]; then
docker build -t $PRO_NAME .
else
docker build --no-cache -t $PRO_NAME .
fi
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
再优化后,支持多个外部传递参数;
sh build.sh -c true -p true
#!/bin/bash
###
# @Author: samy
# @email: yessz#foxmail.com
# @time: 2022-02-12 13:21:47
# @modAuthor: samy
# @modTime: 2022-04-28 15:05:57
# @desc: 构建镜像
# Copyright © 2015~2022 BDP FE
###
source $WORKSPACE/common.sh
IMG_NAME=$(getEnvConf IMG_NAME)
IMG_VERSION=$(getEnvConf IMG_VERSION)
PRO_NAME=$(getEnvConf PRO_NAME)
echo "----IMG_NAME=$IMG_NAME---IMG_VERSION=$IMG_VERSION----PRO_NAME=$PRO_NAME-----"
isCache=false
isPush=false
HARBOR=10.45.xx.116:5000/wdp
while getopts "c:p:" opt; do
case $opt in
c)
echo "参数C的值$OPTARG"
isCache=$OPTARG
;;
p)
echo "参数P的值$OPTARG"
isPush=$OPTARG
;;
?)
echo "未知参数"
exit 1
;;
esac
done
if [ $isCache == true ]; then
docker build -t $IMG_NAME:$IMG_VERSION .
else
docker build --no-cache -t $IMG_NAME:$IMG_VERSION .
fi
if [ $isPush == true ]; then
# docker tag autorun-pro 10.45.46.116:5000/wdp/autorun-pro:latest
# docker push 10.45.46.116:5000/wdp/autorun-pro:latest
docker tag $IMG_NAME:$IMG_VERSION $HARBOR/$IMG_NAME:$IMG_VERSION
docker push $HARBOR/$IMG_NAME:$IMG_VERSION
fi
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
加入提示功能:
#使用说明,用来提示输入参数
usage() {
echo "Usage: sh 执行脚本.sh [init]"
exit 1
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"init")
init
;;
*)
usage
;;
esac
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 容器启动脚本start.sh
sh start.sh true
#!/bin/bash
###
# @Author: samy
# @email: yessz#foxmail.com
# @time: 2022-02-18 13:21:47
# @modAuthor: samy
# @modTime: 2022-03-07 10:05:21
# @desc: 容器启动
# Copyright © 2015~2022 BDP FE
###
PRO_NAME=autorun-pro
PRO_VERSION=latest
isRemove=false
if [ $1 ]; then
isRemove=$1
fi
if [ $isRemove == true ]; then
echo "---容器stop,rm---再run处理---"
docker stop $PRO_NAME
docker rm $PRO_NAME
fi
EXIST=`docker ps -a | grep $PRO_NAME | wc -l`
if [ $EXIST -ne 0 ]; then
STATUS=`docker inspect -f '{{.State.Status}}' $PRO_NAME`
case $STATUS in
"running")
echo "---容器是running状态---将不做处理---"
;;
"exited")
echo "---容器是exited状态---将start处理..."
docker start $PRO_NAME
;;
"paused")
echo "---容器是paused状态---将unpause处理..."
docker unpause $PRO_NAME
;;
"created")
echo "---容器是created状态---将start处理..."
docker start $PRO_NAME
;;
*)
echo "---容器是特殊状态---暂时没有处理..."
esac
else
echo "---检查到容器不存在---将run处理中..."
mkdir -p /home/wdp/autorun/role_template
cp ./host_role.csv /home/wdp/autorun/role_template/host_role.csv
docker run -d \
-p 28080:80 -p 26379:6379 -p 23306:3306 \
-v /data/autorun/mysql/log:/var/log/mysql \
-v /data/autorun/mysql/data:/var/lib/mysql \
-v /home/wdp/autorun/role_template:/root/app/autorun/role_template \
--name $PRO_NAME $PRO_NAME:$PRO_VERSION
fi
sleep 5
docker ps -a | grep $PRO_NAME
# docker exec -it autorun-pro bash
# curl localhost
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
--privileged
参数:
参数启动容器--privileged
否则SSH连接异常;
# 清空无用容器/镜像脚本clean.sh
开始版本TODO
#!/bin/bash
docker stop $(docker ps -a | grep "Exited" | awk '{print $1 }') #停止容器
docker rm $(docker ps -a | grep "Exited" | awk '{print $1 }') #删除容器
docker rmi $(docker images | grep "none" | awk '{print $3}') #删除镜像
2
3
4
只做none的镜像处理:
#!/bin/bash
###
# @Author: samy
# @email: yessz#foxmail.com
# @time: 2022-02-18 13:21:47
# @modAuthor: samy
# @modTime: 2022-03-04 14:51:31
# @desc: 移除不必要的容器和镜像
# Copyright © 2015~2022 BDP FE
###
# set +e
# docker rmi $(docker images | grep "none" | awk '{print $3}')
# ctnExit=`docker ps -a | grep "Exited" | awk '{print $1 }' | wc -l`
# imgNone=`docker images | grep "none" | awk '{print $3}' | wc -l`
# if [ $ctnExit -ne 0 ];then
# echo "111"
# # docker rm -v $(docker ps -aq -f status=exited)
# docker stop $(docker ps -a | grep "Exited" | awk '{print $1 }')
# docker rm $(docker ps -a | grep "Exited" | awk '{print $1 }')
# if [ $imgNone -ne 0 ];then
# echo "333"
# docker rmi $(docker images | grep "none" | awk '{print $3}')
# else
# echo "444"
# fi
# else
# echo "222"
# if [ $imgNone -ne 0 ];then
# echo "555"
# docker rmi $(docker images | grep "none" | awk '{print $3}')
# else
# echo "666"
# fi
# fi
function try(){
[[ $- = *e* ]]; SAVED_OPT_E=$?
set +e
}
function throw(){
exit $1
}
function catch(){
export ex_code=$?
(( $SAVED_OPT_E )) && set +e
return $ex_code
}
export AnException=100
try
(
echo "------remove none images------"
docker rmi $(docker images | grep "none" | awk '{print $3}') && throw $AnException
echo "------finished------"
)
catch || {
case $ex_code in
$AnException)
echo "AnException was thrown"
;;
*)
echo "An unexpected exception was thrown"
throw $ex_code
;;
esac
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 动态构建部署
# 构建思路
总的四个JKS项目,构建联动;
【门户项目一工程】 变动 + 【巡检项目一工程】 变动 生成后zip和jar文件拷贝上传到files目录[httpd]服务;
===> 触发下游【Dockerfile构建】不用缓存方式构建
===>【启动容器项目】销毁后再重新拉起来;
# 实践配置
# 前端门户项目
autorun-web-dev
库设置
shell
envName=awdp
httpdPath=/var/www/html/files/autorun/pro/portal
cd $WORKSPACE
rm -rf dist dist.zip
cd ./node
npm install --registry=https://registry.npm.taobao.org/
npm run git addUser xx xx=
npm run clone env=$envName
cd ../
npm install --registry=https://registry.npm.taobao.org/
npm run build env=$envName
zip -r AAWeb.zip dist
cp -rf AAWeb.zip $httpdPath/
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
设置后面构建项目
# docker项目
autorun-docker-dev
配置设置
设置构建依赖项目
shell
PRO_NAME=autorun-pro
PRO_VERSION=0.1.0
cd $WORKSPACE/pro
sh build.sh
#上传私有镜像Docker hub
docker tag $PRO_NAME 10.xxx:5000/wdp/$PRO_NAME:$PRO_VERSION
docker push 10.xxx:5000/wdp/$PRO_NAME:$PRO_VERSION
#查看是否构建成功
docker images |grep $PRO_NAME
#移除多余的none和没用的容器
#sh remove-none-img.sh
2
3
4
5
6
7
8
9
10
11
12
13
14
# 总体依赖
# 实践
# 备份
# Dockerfile
###
# @Author: samy
# @email: yessz#foxmail.com
# @time: 2022-02-12 13:21:47
# @modAuthor: samy
# @modTime: 2022-02-28 13:28:20
# @desc: Dockerfile
# Copyright © 2015~2022 BDP FE
###
FROM centos:centos7
LABEL author=samyzh version=0.1.0
RUN yum -y install yum-utils make gcc-c++ libtool zlib zlib-devel unzip zip gettext pcre pcre-devel openssl openssl-devel wget \
&& yum -y install openssh-server openssh-clients \
&& yum -y install libaio net-tools numactl\
&& yum clean all
ENV LANG en_US.UTF-8
ENV WORKDIR=/srv/app
ENV URLBASE=http://xxxx:58888/files/autorun/pro
WORKDIR $WORKDIR
ADD entrypoint.sh .
RUN mkdir -p $WORKDIR/soft/nginx && cd $WORKDIR/soft/nginx \
&& wget $URLBASE/soft/nginx/nginx-1.18.0.tar.gz \
&& wget $URLBASE/soft/nginx/nginx.conf \
&& mkdir -p $WORKDIR/soft/redis && cd $WORKDIR/soft/redis \
&& wget $URLBASE/soft/redis/redis-3.2.11.tar.gz \
&& wget $URLBASE/soft/redis/redis.conf \
&& mkdir -p $WORKDIR/soft/mysql && cd $WORKDIR/soft/mysql \
&& wget $URLBASE/soft/mysql/mysql-5.7.35.tar.gz \
&& wget $URLBASE/soft/mysql/my.cnf \
&& wget $URLBASE/soft/mysql/init.sql \
&& wget $URLBASE/soft/mysql/setpwd.sql \
&& mkdir -p $WORKDIR/soft/jdk && cd $WORKDIR/soft/jdk \
&& wget $URLBASE/soft/jdk/jdk-8u241-linux-x64.tar.gz
RUN mkdir -p $WORKDIR/portal && cd $WORKDIR/portal \
&& wget $URLBASE/portal/AAWeb.zip \
&& wget $URLBASE/portal/eureka.zip \
&& wget $URLBASE/portal/GSMAppService.zip \
&& wget $URLBASE/portal/dataportal.sql \
&& mkdir -p $WORKDIR/autorun && cd $WORKDIR/autorun \
&& wget $URLBASE/autorun/autorun.tar.gz \
&& wget $URLBASE/autorun/zookeeper-3.4.8.tar.gz \
&& wget $URLBASE/autorun/autorun.sql \
&& wget $URLBASE/autorun/update.tar.gz
# install nginx
RUN cd $WORKDIR/soft/nginx \
&& tar -zxvf nginx-1.18.0.tar.gz \
&& cd nginx-1.18.0 && ./configure --prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
&& make && make install\
&& ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx \
&& rm -rf ../*.gz \
&& cp -rf $WORKDIR/soft/nginx/nginx.conf /usr/local/nginx/conf/
# install redis
RUN cd $WORKDIR/soft/redis \
&& tar -zxvf redis-3.2.11.tar.gz \
&& cd redis-3.2.11 && make install PREFIX=/usr/local/redis \
&& ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli \
&& ln -s /usr/local/redis/bin/redis-server /usr/bin/redis \
&& rm -rf ../redis-3.2* \
&& cp -rf $WORKDIR/soft/redis/redis.conf /usr/local/redis/
# install mysql
# RUN yum install -y libaio net-tools numactl
RUN useradd -s /sbin/nologin mysql \
&& mkdir -p /var/lib/mysql/data \
&& chown -R root /var/lib/mysql \
&& chown -R mysql:mysql /var/lib/mysql \
&& chown -R mysql /var/lib/mysql/data
RUN cd $WORKDIR/soft/mysql \
&& tar -zxvf mysql-5.7.35.tar.gz \
&& cd mysql-5.7.35 \
&& rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm \
&& rm -rf ../mysql-5.7* \
&& cp -rf $WORKDIR/soft/mysql/my.cnf /etc/my.cnf
# install jdk
RUN cd $WORKDIR/soft/jdk \
&& tar -zxvf jdk-8u241-linux-x64.tar.gz \
&& mv jdk1.8.0_241/ /usr/local/java/ \
&& rm -rf *.gz
ENV JAVA_HOME=/usr/local/java
ENV JRE_HOME=/usr/local/java/jre
ENV CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH=$PATH:$JAVA_HOME/bin
# pro
RUN cd $WORKDIR/portal \
&& unzip -o $WORKDIR/portal/eureka.zip \
&& unzip -o $WORKDIR/portal/GSMAppService.zip \
&& unzip -o $WORKDIR/portal/AAWeb.zip \
&& mv dist AAWeb \
&& rm -rf *.zip
RUN cd $WORKDIR/autorun \
&& tar -zxvf zookeeper-3.4.8.tar.gz \
&& tar -zxvf autorun.tar.gz \
&& tar -zxvf update.tar.gz \
&& rm -rf *.gz
EXPOSE 80 6379 3306
ENTRYPOINT ["/bin/bash", "./entrypoint.sh"]
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# entrypoint.sh
#!/bin/bash
###
# @Author: samy
# @email: yessz#foxmail.com
# @time: 2022-02-12 13:21:47
# @modAuthor: samy
# @modTime: 2022-03-03 14:25:40
# @desc: 初始化;启动sshd,redis,mysqld,nginx,数据库脚本初始化
# Copyright © 2015~2022 BDP FE
###
set -e
# 主机默认密码
ROOT_PWD=xxx
# 数据库最终密码
MYSQL_PWD=xxx
# 初始化文件flag
FLAG_FILE=.initFlag
# autorun相关改动比较大的jar
JAR_MGR=autorun-manager-1.0.jar
JAR_CLD=autorun-collectdata-1.0-SNAPSHOT-jar-with-dependencies.jar
JAR_AGT=autorun-agent-1.0.jar
# =============================================初始化系统必要的相关服务======================================================
if [ -f $FLAG_FILE ]; then
echo "进入容器restart模式..."
echo "重启sshd..."
/usr/sbin/sshd -D &
echo "重启redis..."
redis /usr/local/redis/redis.conf
echo "重启mysqld..."
mysqld --defaults-file=/etc/my.cnf --user root &
sleep 10
else
echo "容器init初始化模式..."
# 默认容器密码
echo "root:${ROOT_PWD}" | chpasswd
#start sshd
ssh-keygen -A
#免密码本机跳本机
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
echo "启动sshd..."
/usr/sbin/sshd -D &
echo "启动redis..."
redis /usr/local/redis/redis.conf
# nginx -c /usr/local/nginx/conf/nginx.conf
# start mysql and init sql
rm -rf /var/lib/mysql/* && mysqld --initialize --user=mysql --basedir=/var/lib/mysql
mysqld --defaults-file=/etc/my.cnf --user root --skip-grant-tables &
sleep 10
mysql -uroot mysql </srv/app/soft/mysql/setpwd.sql
ps -ef | grep mysqld | grep -v grep | awk '{print "kill -9",$2}' | sh
echo "启动mysqld..."
mysqld --defaults-file=/etc/my.cnf --user root &
sleep 10
mysql -uroot -p$ROOT_PWD --connect-expired-password mysql </srv/app/soft/mysql/init.sql
echo "初始化数据库..."
mysql -uroot -p$MYSQL_PWD -e "
CREATE DATABASE IF NOT EXISTS dataportal DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE DATABASE IF NOT EXISTS autorun DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
quit
"
echo "导入门户数据..."
mysql -uroot -p$MYSQL_PWD dataportal </srv/app/portal/dataportal.sql
echo "导入巡检后端数据..."
mysql -uroot -p$MYSQL_PWD autorun </srv/app/autorun/autorun.sql
#创建软链: 只做一次处理
mkdir -p /usr/lib/jvm/
ln -s /usr/local/java /usr/lib/jvm/jdk1.8.0_241
mkdir -p /usr/java/jdk1.7.0_67-cloudera/bin
ln -s /usr/local/java/bin/java /usr/java/jdk1.7.0_67-cloudera/bin/java
#创建脚本路径
mkdir -p /root/app/autorun/scripts/ /root/app/autorun/agents/
cp -r /srv/app/autorun/autorun/scripts/* /root/app/autorun/scripts/
#更新jar的运行时程序
ln -s /srv/app/autorun/autorun/$JAR_CLD /root/app/autorun/agents/$JAR_CLD
#记录初始化过
touch $FLAG_FILE
echo "脚本初始化完成..."
fi
# =============================================目录迁移及软引用配置======================================================
#要更新的.jar ,先屏蔽了,暂时不用;
cd /srv/app/autorun/update
if [ -f ./$JAR_MGR ]; then
mv -f $JAR_MGR ../autorun/
fi
if [ -f ./$JAR_CLD ]; then
mv -f $JAR_CLD ../autorun/
fi
if [ -f ./$JAR_AGT ]; then
mv -f $JAR_AGT ../autorun/agents/agent_123/agent/
fi
# =============================================启动门户,巡检和agent======================================================
echo "启动eureka..."
cd /srv/app/portal/eureka && sh stop.sh && sh start.sh
sleep 5
echo "启动GSMAppService..."
cd /srv/app/portal/GSMAppService && sh stop.sh && sh start.sh
sleep 5
echo "启动zookeeper..."
cd /srv/app/autorun/zookeeper-3.4.8/bin && chmod +x zkServer.sh && ./zkServer.sh start
sleep 5
echo "启动autorun..."
cd /srv/app/autorun/autorun/ && sh start.sh
sleep 5
echo "启动agent..."
cd /srv/app/autorun/autorun/agents/agent_123/agent && kill -9 `cat pidfile.txt` && sh agent_run.sh
sleep 5
# echo "主机角色导入..."
# cd /srv/app/autorun/autorun && sh send.sh
# sleep 5
echo "初步启动完成..."
# netstat -antlp
echo "启动nginx..."
nginx -g "daemon off;"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# pkg导出部署
# 相关脚本
pkg.sh
#!/bin/bash
###
# @Author: samy
# @email: yessz#foxmail.com
# @time: 2022-02-12 13:21:47
# @modAuthor: samy
# @modTime: 2022-03-07 10:31:40
# @desc: 发布现场部分
# Copyright © 2015~2022 BDP FE
###
PRO_NAME=autorun-pro
PRO_VERSION=0.1.0
HTTPD_PATH=/var/www/html/files/autorun/pro/pkg
DATETIME=`date +%Y%m%d%H%M%S`
mkdir ./images
docker save $PRO_NAME | gzip > ./images/$PRO_NAME:$PRO_VERSION.tar.gz
#docker export $PRO_NAME | gzip > ./images/$PRO_NAME:$PRO_VERSION.tar.gz
mv ./images $HTTPD_PATH/
mv start.sh $HTTPD_PATH/
cd $HTTPD_PATH && tree -h
echo "---压缩gz包用于发布---"
cd ../ && tar zcvf ./pkg-bak/$PRO_NAME-$PRO_VERSION-$DATETIME.tar.gz ./pkg/
ls -lh
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
start.sh
#!/bin/bash
###
# @Author: samy
# @email: yessz#foxmail.com
# @time: 2022-02-12 13:21:47
# @modAuthor: samy
# @modTime: 2022-03-07 10:31:40
# @desc: 发布现场部分
# Copyright © 2015~2022 BDP FE
###
PRO_NAME=autorun-pro
PRO_VERSION=0.1.0
# import
# docker save autorun-pro | gzip > ./images/autorun-pro:0.1.0.tar.gz
# docker load < ./images/autorun-pro:0.1.0.tar.gz
# docker import autorun-pro:1.0.0 ./images/autorun-pro:1.0.0.tar.gz
# docker save $PRO_NAME | gzip > ./images/$PRO_NAME:$PRO_VERSION.tar.gz
docker load < ./images/$PRO_NAME:$PRO_VERSION.tar.gz
#docker import ./images/$PRO_NAME:$PRO_VERSION.tar.gz
# # stop
# docker stop $PRO_NAME
# docker rm $PRO_NAME
#start
echo "----准备好初始化host_role.csv-----"
mkdir -p /data/autorun/autorun/role_template
cp ./host_role.csv /data/autorun/autorun/role_template/host_role.csv
echo "---run...---"
docker run -d \
--privileged \ # 支持centos6 ssh centos7内部
-p 38080:80 -p 36379:6379 -p 33306:3306 \
-v /data/autorun/mysql/log:/var/log/mysql \
-v /data/autorun/mysql/data:/var/lib/mysql \
-v /data/autorun/autorun/role_template:/root/app/autorun/role_template \
--name $PRO_NAME $PRO_NAME:$PRO_VERSION
# docker exec -it autorun-pro bash
# curl localhost
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 配合jks做Tag
# 镜像优化
# 优化后改成export/import
镜像可以压缩到1G左右,符合方便钉钉传输;
最后发现是具有现有的容器才能打镜像,不合适现在场景;
# docker export -o autorun-pro.tar autorun-pro
# docker export autorun-pro > autorun-pro2.tar
# docker export autorun-pro | gzip > autorun-pro2.tar.gz
#pkg.sh
# docker save $PRO_NAME | gzip > ./images/$PRO_NAME:$PRO_VERSION.tar.gz
docker export $PRO_NAME | gzip > ./images/$PRO_NAME:$PRO_VERSION.tar.gz
docker export autorun-pro | gzip > ./images/autorun-pro:1.0.2.tar.gz
#start.sh
# docker load < ./images/$PRO_NAME:$PRO_VERSION.tar.gz
docker import ./images/$PRO_NAME:$PRO_VERSION.tar.gz
docker import ./images/autorun-pro:1.0.2.tar.gz
#实践
docker ps -a | autorun-pro # 确保容器存在后,再导出镜像;
docker export autorun-pro | gzip > ./images/autorun-pro:1.0.2.tar.gz
docker export autorun-pro | gzip -o ./images/autorun-pro:1.0.2.tar.gz
docker images | grep autorun-pro
docker import ./images/autorun-pro:1.0.2.tar.gz autorun-pro:1.0.2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# experimental 参数设置为 true
没什么效果;待再次实验下;
sudo service docker restart
docker version
docker version -f '{{.Server.Experimental}}'
docker system info
docker build --no-cache --squash -t autorun-pro2 .
2
3
4
5
6
7
# RUN全部完全合并
压缩少了1G+; 3.93G压缩到2.71G
RUN mkdir -p $WORKDIR/soft/nginx && cd $WORKDIR/soft/nginx \
&& wget $URLBASE/soft/nginx/nginx-1.18.0.tar.gz \
&& wget $URLBASE/soft/nginx/nginx.conf \
&& mkdir -p $WORKDIR/soft/redis && cd $WORKDIR/soft/redis \
&& wget $URLBASE/soft/redis/redis-3.2.11.tar.gz \
&& wget $URLBASE/soft/redis/redis.conf \
&& mkdir -p $WORKDIR/soft/mysql && cd $WORKDIR/soft/mysql \
&& wget $URLBASE/soft/mysql/mysql-5.7.35.tar.gz \
&& wget $URLBASE/soft/mysql/my.cnf \
&& wget $URLBASE/soft/mysql/init.sql \
&& wget $URLBASE/soft/mysql/setpwd.sql \
&& mkdir -p $WORKDIR/soft/jdk && cd $WORKDIR/soft/jdk \
&& wget $URLBASE/soft/jdk/jdk-8u241-linux-x64.tar.gz \
# download pro info
&& mkdir -p $WORKDIR/portal && cd $WORKDIR/portal \
&& wget $URLBASE/portal/AAWeb.tar.gz\
&& wget $URLBASE/portal/eureka.tar.gz\
&& wget $URLBASE/portal/GSMAppService.tar.gz\
&& wget $URLBASE/portal/dataportal.sql \
&& mkdir -p $WORKDIR/autorun && cd $WORKDIR/autorun \
&& wget $URLBASE/autorun/autorun.tar.gz \
&& wget $URLBASE/autorun/zookeeper-3.4.8.tar.gz \
&& wget $URLBASE/autorun/autorun.sql \
# install nginx
&& cd $WORKDIR/soft/nginx \
&& tar -zxvf nginx-1.18.0.tar.gz \
&& cd nginx-1.18.0 && ./configure --prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
&& make && make install\
&& ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx \
&& rm -rf ../*.gz \
&& cp -rf $WORKDIR/soft/nginx/nginx.conf /usr/local/nginx/conf/ \
# install redis
&& cd $WORKDIR/soft/redis \
&& tar -zxvf redis-3.2.11.tar.gz \
&& cd redis-3.2.11 && make install PREFIX=/usr/local/redis \
&& ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli \
&& ln -s /usr/local/redis/bin/redis-server /usr/bin/redis \
&& rm -rf ../redis-3.2* \
&& cp -rf $WORKDIR/soft/redis/redis.conf /usr/local/redis/ \
# install mysql
&& useradd -s /sbin/nologin mysql \
&& mkdir -p /var/lib/mysql/data \
&& chown -R root /var/lib/mysql \
&& chown -R mysql:mysql /var/lib/mysql \
&& chown -R mysql /var/lib/mysql/data \
&& cd $WORKDIR/soft/mysql \
&& tar -zxvf mysql-5.7.35.tar.gz \
&& cd mysql-5.7.35 \
&& rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm \
&& rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm \
&& rm -rf ../mysql-5.7* \
&& cp -rf $WORKDIR/soft/mysql/my.cnf /etc/my.cnf \
# install jdk
&& cd $WORKDIR/soft/jdk \
&& tar -zxvf jdk-8u241-linux-x64.tar.gz \
&& mv jdk1.8.0_241/ /usr/local/java/ \
&& rm -rf *.gz \
# pro
&& cd $WORKDIR/portal \
&& tar -zxvf eureka.tar.gz\
&& tar -zxvf GSMAppService.tar.gz\
&& tar -zxvf AAWeb.tar.gz\
&& mv dist AAWeb \
&& rm -rf *.gz \
&& cd $WORKDIR/autorun \
&& tar -zxvf zookeeper-3.4.8.tar.gz \
&& tar -zxvf autorun.tar.gz \
&& rm -rf *.gz
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74