The original article is reprinted from liu Yue’s Technology blog v3u.cn/a_id_84
In general, the process for deploying a project to production is as follows:
Requirement analysis – Prototype design – Code development – Intranet deployment – Submit test – Confirm online – Back up data – Update on the Internet – Final test. If the code deployed on the Internet is abnormal, roll back it in time.
The whole process is quite complicated and lengthy, and involves entering many commands, such as uploading code, pulling git or merging branches, etc.
Jenkins is a very popular continuous integration tool, which can help you automatically deploy the updated code to run on the server. The whole process is very automated, you can understand it as a visual interface of deployment command operation.
There are three main ways to install Jenkins
Download the official WAR package and run it directly in Tomcat. Yum installation. Use the official Docker image.
There is no doubt that there is no need to choose the first two complicated installation methods when docker is so simple and convenient.
First, install docker
Centos installation docker 1 Docker requires a centos operating system kernel version later than 3.10. Check the prerequisites on this page to verify whether your centos version supports Docker. Make sure the YUM package is up to date. Sudo yum remove docker docker-common docker-selinux docker-engine sudo yum remove docker docker-common docker-selinux Yum-util provides yum-config-manager functionality, Y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y - add - repo https://download.docker.com/linux/centos/docker-ce.repo all docker version 6, you can view all warehouse, And select a specific version installed yum list docker - ce - showduplicates | sort - r 7, install the docker sudo yum install docker - ce powered up for 8, start, and add sudo systemctl start docker sudo systemctlenableDocker 9, verify whether the installation is successful (there are two parts of the client and service indicates that docker installation and startup are successful) docker versionCopy the code
Then download the official Jenkins Docker image
docker pull jenkins/jenkins
Copy the code
View mirror Docker images
Create a directory on the host and add read and write permissions so that the Jenkins application can read and write files while running
mkdir /root/j_node
chmod 777 /root/j_node
Copy the code
In the background, the image serves as a container, maps ports, and mounts the newly created directory to the container
docker run -d --name jenkins -p 8081:8080 -p 50000:50000 -v /root/j_node:/var/jenkins_home jenkins/jenkins
Copy the code
Note here that if it is Ali Cloud, the security policy needs to expose port 8081
Visit http:// your IP address :8081
Then run the command to obtain the installation key
docker logs jenkins
Copy the code
Once you have the password, enter it and install the recommended plug-in, which includes the version control software Git.
After the end, according to the prompts to set up the login account
Then create a new project and enter your project’s online Git repository address in the source control column. Note that the default is the master branch, because the code deployed in production must be the master branch
After saving, click Build Now to deploy, Jenkins will automatically extract the latest master branch from git version library for deployment, and the history record of every deployment will be saved
In this case, go to the /root/j_node directory and find that the project has been deployed in the workspace directory
The whole process is very simple. Before going online each time, the project manager only needs to check the codes of each team member, and then unify them into the master branch. Finally, enter Jenkins and click the deployment button, which saves a lot of time.
The original article is reprinted from liu Yue’s Technology blog v3u.cn/a_id_84