CICD combat-using Jenkins to achieve automated deployment and environment isolation

CICD combat-using Jenkins to achieve automated deployment and environment isolation

installation

jdk

1. Check if jdk is installed

[root@10-0-59-231 data]# java -version # 查看是否安装jdk,没有则要安装
-bash: java: 未找到命令

2. Search for available packages

yum search java |grep -i --color JDK

3. Install jdk

yum install java-1.8.0-openjdk* # 安装1.8 openjdk

4. View

java -version

#输出
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

PS: yum automatically configure the environment variables, you can / profile vim / etc View

jenkins

1. Install under centos 7

yum install jenkins

2. Change the default port number and git clone code storage directory

vim /etc/sysconfig/jenkins
JENKINS_PORT="8088"             # 默认8080
JENKINS_HOME="/data/jenkins"    # 默认 /var/lib/jenkins
systemctl daemon-reload # 使得配置生效

3. Start

systemctl restart jenkins # 重启
chkconfig jenkins on      # 开机启动

Configuration

1. Create a new task
. 2. Enter a name and select free style software.
Insert picture description here
3.General, check to discard the old build
Insert picture description here

4. Set up the code warehouse. We use gitlab, so check Git, then paste the code repository address, Credentials add a user with permission.
Branch Specifier: The default is to pull the code from the Master to compile, we generally release is release, so the release branch is used here.
Insert picture description here

5. Build triggers. This does not need to be set up, it is not used.
6. Build the environment. Not used temporarily, skip it.
7. Build. Click "Execute Shell" to call the build.sh script to complete the compilation of the source code, see the next section for details.
Insert picture description here

8. After the build. Click "Send build artifacts over SSH" to publish the compiled package to the remote machine via ssh, see below for details.
Insert picture description here

Construct

1. Build the script.

cd ${WORKSPACE} && cd server/paas_build
chmod 777 build_db_proxy_server.sh
./build_db_proxy_server.sh
cd ../
echo 'tar ${pwd}/online.base.im/'
tar -czvf online.base.im.tar.gz online.base.im/

Insert picture description here

Pack and compress here to facilitate subsequent copy distribution.

2. Test the build.
Insert picture description here
Insert picture description here

Click Build Now, and then you can see the build progress below, and then click again to view the specific build results.
Insert picture description here

distribution

Added SSH Servers

PS: After the program is compiled locally, it needs to be copied to the target machine and run to complete the whole process.
Click System Management -> System Settings, and drag it to the bottom. Find SSH Servers and click Add.
Insert picture description here
Enter the relevant information, including the Remote Directory, which needs to be created in advance. It is recommended to be in directories such as /data/apps. This directory represents the root directory of the subsequent copy of the file to the machine. Then click Advanced Settings Password, click "Test Connfiguration" to make sure the configuration is ok.
Insert picture description here
If there are multiple machines, add multiple times.

Publish script

1. After the build is completed, you need to perform some installation actions through scripts, click "Send build artifacts over SSH".
2. Choose a server. Compared to WorkSpace, my package is located at server/online.base.im.tar.gz.
Insert picture description here
Remove prefix: The prefix to be removed, if not set. Assuming that the Remote Directory set by SSH Servers is /data/webapps, the path after the compressed package is copied is: /data/webapps/server/online.base.im.tar.gz.
Exec command: The command to be executed. Please set the current working directory before execution, such as cd /data/webapps.

Attached script:

kill -9 $(pidof db_proxy_server) # 停止进程
sleep 5    # 等一会
cd /data/webapps/ 
# 备份原程序
mv online.base.imdbproxyserver.service online.base.imdbproxyserver.service.$(date "+%Y%m%d")${BUILD_NUMBER}
tar -zxvf online.base.im.tar.gz
rm -rf online.base.im.tar.gz
mv online.base.im online.base.imdbproxyserver.service
cd online.base.imdbproxyserver.service
cd db_proxy_server
mv libhiredis.so.0.13 libhiredis.so.0.12
ln -s /data/webconf/dbproxyserver.xml dbproxyserver.xml
cd ../
chmod 777 *.sh
./restart.sh db_proxy_server

rebuild

Insert picture description here

At this time, you should keep adjusting the script until it shows a blue ball, which means that everything went smoothly in the middle without errors. Then it is achieved:

  1. Automatically pull the latest code from gitlab
  2. Compile
  3. Automatically deploy the cluster

Take a look at the effect:
Insert picture description here
Insert picture description here
PS: If you need to publish to multiple machines, just add an SSH Server in the "post-build" section.

on

CSDN about the author
recommend your own open source IM, written in pure Golang:

CoffeeChat:
https://github.com/xmcy0011/CoffeeChat
opensource im with server(go) and client(flutter+swift)

Referred to well-known projects such as TeamTalk and Guazi IM, including server (go) and client (flutter+swift), single chat and robot (micro, Turing, Sizhi) chat functions have been completed, and group chat functions are currently being developed , Welcome friends Star who are interested in golang and cross-platform development of flutter technology to pay more attention.

————————————————
Copyright statement: This article is the original article of CSDN blogger "Xu Fei", and it follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this for reprinting. statement.
Original link: https://blog.csdn.net/xmcy001122/article/details/105665732

Reference: https://www.jianshu.com/p/5f671aca2b5a
Reference: http://www.linuxboy.net/linuxjc/144365.html

Guess you like

Origin blog.csdn.net/xmcy001122/article/details/106202085