查看系统名称、节点名称、版本号等,执行命令
uname -a
更新yum,安装依赖包
yum update
yum install -y yum-utils device-mapper-persistent-data lvm2
设置阿里云镜像源
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装 Docker-CE
yum update -y && yum install -y docker-ce
需要等几分钟,执行完成后,如下图:
创建 /etc/docker 目录
mkdir /etc/docker
配置镜像加速器 daemon
cat > /etc/docker/daemon.json <
创建systemd Service相关目录
mkdir -p /etc/systemd/system/docker.service.d
重启docker服务,看到docke相关信息,表示安装成功
systemctl daemon-reload && systemctl restart docker && systemctl enable docker
docker version
安装docker compose
curl -L https://github.com/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
执行了docker-compose --version后输出如下所示表示安装成功
docker-compose version
如果有从其他系统上导出docker镜像,再执行如下步骤,没有可直接跳过
cd /usr/local/install-loit/
tar -zxvf /root/images.tar.gz
vim load-images.sh
#!/bin/bash
ls /usr/local/install-loit/ > /tmp/image-list.txt
cd /usr/local/install-loit/
for i in $( cat /tmp/image-list.txt)
do
docker load -i $i
done
rm -rf /tmp/image-list.txt
chmod a+x load-images.sh
./load-images.sh
前台运行
docker-compose up
后台运行
docker-compose up -d
启动
docker-compose start
停止
docker-compose stop
停止并移除容器
docker-compose down
root 访问容器
docker exec -it -u root
拷贝文件
拷贝出来
docker cp wiki_confluence:/opt/atlassian/confluence/confluence/WEB-INF/lib/atlassian-extras-decoder-v2-3.4.1.jar /opt/docker/mysql
拷贝进去
docker cp atlassian-extras-decoder-v2-3.4.1.jar wiki_confluence:/opt/atlassian/confluence/confluence/WEB-INF/lib/atlassian-extras-decoder-v2-3.4.1.jar
Docker保存修改后的镜像
docker commit afcaf46e8305 centos-vim
查看镜像centos-vim
docker images | grep centos-vim
查看镜像的详细信息:
docker inspect centos-vim:afcaf46e8305
删除镜像
docker image rm e2f5e9044b5e
删除容器
docker container rm ccc
使用mkdir创建/usr/local/loit/soft/docker/jenkins目录,切换到该目录下
cd /usr/local/loit/soft/docker/jenkins
配置docker-compose.yml
vi docker-compose.yml
将下面代码粘贴到docker-compose.yml中
version: '3.1'
services:
jenkins:
restart: always
image: jenkins/jenkins:centos
container_name: jenkins
ports:
# 发布端口
- 12012:8080
# 基于 JNLP 的 Jenkins 代理通过 TCP 端口 50000 与 Jenkins master 进行通信
#- 50000:50000
environment:
- "TZ=Asia/Shanghai"
- "PATH=$PATH:$HOME/bin:/var/local/apache-maven-3.6.3/bin"
#volumes:
#- ./data:/var/jenkins_home
#- /var/run/docker.sock:/var/run/docker.sock
#- /usr/bin/docker:/usr/bin/docker
启动 jenkins
docker-compose up -d
wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
将安装包copy到jenkins中的root路径下
docker cp apache-maven-3.6.3-bin.tar.gz jenkins:/root/
进入docker容器中,切换到root路径下
docker exec -u root -it jenkins bash
cd /root/
对maven压缩包进行解压,并移动到/var/local/路径下
tar -zxvf apache-maven-3.6.3-bin.tar.gz
mv apache-maven-3.6.3 /var/local/
配置maven环境变量
vi .bash_profile
增加如下
PATH=$PATH:$HOME/bin:/var/local/apache-maven-3.6.3/bin
执行source .bash_profile,使配置生效
source .bash_profile
查看maven版本,安装成功后,退出docker
mvn -version
exit
下载 NodeJS
https://cdn.npm.taobao.org/dist/node/v12.18.3/node-v12.18.3-linux-x64.tar.gz
上传到路径 /usr/local/loit/soft
cd /usr/local/loit/soft
docker cp node-v12.18.3-linux-x64.tar.gz jenkins:/root/
docker exec -u root -it jenkins bash
在jenkins容器内执行以下步骤
cd /root/
tar -zxvf node-v12.18.3-linux-x64.tar.gz
mv node-v12.18.3-linux-x64 /usr/local/
cd /usr/local/node-v12.18.3-linux-x64/bin
./node -v
ln -s /usr/local/node-v12.18.3-linux-x64/bin/node /usr/local/bin
ln -s /usr/local/node-v12.18.3-linux-x64/bin/npm /usr/local/bin
修改jenkins容器中中文编码
[root@b0ae5207cf56 /]# vi /etc/locale.conf
#LANG="en_US.UTF-8"
LANG=zh_CN.GBK
[root@b0ae5207cf56 /]# source /etc/locale.conf
[root@b0ae5207cf56 /]# exit
查看docker,显示正在运行的容器
docker ps
根据containerId,创建新镜像
docker commit 5d81d56b18b6 jenkins/jenkins:centos.v1
切换到/usr/local/loit/soft/docker/jenkins路径下,修改docker-
compose.yml
cd /usr/local/loit/soft/docker/jenkins
vi docker-compose.yml
修改镜像,修改挂载点
version: '3.1'
services:
jenkins:
restart: always
image: jenkins/jenkins:centos.v1
container_name: jenkins
ports:
# 发布端口
- 12012:8080
# 基于 JNLP 的 Jenkins 代理通过 TCP 端口 50000 与 Jenkins master 进行通信
#- 50000:50000
environment:
- "TZ=Asia/Shanghai"
- "PATH=$PATH:$HOME/bin:/var/local/apache-maven-3.6.3/bin"
volumes:
- ./data:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
授权
chmod 777 /usr/local/loit/soft/docker/jenkins/data
chmod 777 /var/run/docker.sock
chmod 777 /usr/bin/docker
删除之前的容器
docker-compose down
重启
docker-compose up -d
浏览器打开http://114.100.100.24:12012/
进入到docker容器中,获取初始密码
cat /usr/local/loit/soft/docker/jenkins/data/secrets/initialAdminPassword
选择插件安装
勾选上"Publish Over SSH",点击安装,
安装插件耐心等待,看网速,慢的话要好几个小时,安装完成后设置管理员账号并登陆
设置Jenkins
配置maven,maven安装地址为docker容器中的安装地址
配置Git
配置MAVEN_HOME
1.2.1.3设置 Publish over SSH
进入系统配置
源码管理,选择git,使用http链接,点击添加账号密码
点击构建后操作中的高级按钮,“exec in pty”打钩,最后点击保存
需要部署项目时,点击立即构建,执行成功后就可以了
系统管理-》插件管理-》插件
node-v12.18.3
/usr/local/node-v12.18.3-linux-x64
前端项目配置(创建一个自由分格的软件项目)
ssh://[email protected]:12222/spring-timeloit/portalSystem.git
修改成实际的项目路径
其中 cd /var/jenkins_home/workspace/portalSystem 需要修改成构建项目的名称
cd /var/jenkins_home/workspace/portalSystem
npm install node-sass -save --unsafe-perm --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
npm install --unsafe-perm --registry=https://registry.npm.taobao.org
npm run build:prod
rm -rf dist.tar.gz
rm -rf static.tar.gz
tar -zcvf dist.tar.gz dist
tar -zcvf static.tar.gz static
dist.tar.gz,static.tar.gz
/root/temp
其中 /root/temp/deploy-xxx.sh 为 前端部署脚本 可参照 140 /portalSystem/code/
cd /root/temp
tar -zxvf /root/temp/dist.tar.gz
tar -zxvf /root/temp/static.tar.gz
exec /root/temp/deploy-xxx.sh
deploy-xxx.sh 如下
#!/bin/sh
rm -rf dist
rm -rf static
rm -rf vue-permission/static
tar -zxvf /root/temp/dist.tar.gz
tar -zxvf /root/temp/static.tar.gz
cp -r dist/static static
cp -r dist/static vue-permission/static
nohup ./node_modules/http-server/bin/http-server -p 9528 &
exit
1.2.1.6新建视图
http://39.100.100.14:12012/newView
jenkins只识别全路径
修改其权限
chmod 777 deploy-file-6001.sh
例子脚本
#!/bin/sh
echo '---------------kill_loitPortal.jar----------------'
KILL_PROCESS_NAME='/var/www/portal-7009/loit-portal.jar'
PROCESS_ID=`ps -ef | grep $KILL_PROCESS_NAME | grep -v 'grep' | awk '{print $2}'`
echo 'ProcessId: ' $PROCESS_ID
for id in $PROCESS_ID
do
echo 'KILL_ID: ' $id
kill -s 9 $id
done
echo '---------------killed_loitPortal.jar----------------'
echo '---------------start_loitPortal.jar----------------'
nohup /usr/local/java8/jdk1.8.0_11/bin/java -javaagent:/usr/local/loit/soft/skywalking/agent/skywalking-agent.jar -Dskywalking.agent.service_name=loit-portal -Dskywalking.collector.backend_service=39.100.100.10:12001 -Xms768m -Xmx768m -XX:PermSize=256M -XX:MaxPermSize=512M -jar $KILL_PROCESS_NAME --spring.profiles.active=test7009 >/var/www/portal-7009/loit-portal.log 2>&1 &
echo '---------------started_loitPortal.jar----------------'