git+github+jenkins+maven+tomcat deployment (linux)

Foreword:

There are many applications of Jenkins, here I only use one of them, git+github+jenkins+maven+tomcat deployment, to achieve continuous integration and continuous deployment from uploading code files → packaging → online. And summed up a little bit of my experience in deployment and use. Next, I will go online from github, git, Jenkins, and packaging. These four modules will respectively talk about the problems I encountered during the use.

One, github

The main role of GitHub is to build a bridge between git and Jenkins. So for the use of GitHub, only use the id_rsa.pub on the git server that is filled in when using ssh-key.
1. Needless to say, register your GitHub account and password.
2. The usage process is as follows

The first picture The
first slide
second picture The
the second onethird picture The
Insert picture description here
fourth picture The
Fourth
fifth picture The
Fifth
sixth picture
Sixth

That's it for GitHub's configuration.

Two, git

1. git deployment
There are two deployment methods here: the
first is to download the tar package from the mirror warehouse, and then install the dependencies;

~:wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz
~:yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
~:tar –zxvf git-2.9.0.tar.gz
~:cd git-2.9.0
~:./configure --prefix=/hengha/git/   #指定路径
~:make && make install

The second is to install directly with yum, without installation dependencies.

~:yum -y install git

The difference is that the first git version can be selected by yourself, while the second git version is the default and the version is relatively low. The first one is recommended. If you use both methods, you will find that the git version is not 2.9.0 when you use git --version. That's because the system used yum according to its own habits. The system uses /usr/local/bin by default. / Git, this time we need to change the system environment variables.

~:vim /etc/profile
export PATH=/hengha/git/bin:$PATH

~:source /etc/profile

2.
Use of git When you first start using git, you should refer to the example given by GitHub, the third picture in the GitHub section

~:cd /hengha/git/
~:mkdir hengha
~:cd hengha
# 把开发编辑的文件放到这个目录下,就像如下的操作步骤,替换文件内容即可
~:echo "# hengha" >> README.md
~:git init                        # 初始化仓库。。。git的命令基本上跟linux的命令意义是一样的
~:git add README.md               # git add *     
~:git commit -m "first commit"    # 可以具体去了解下git的工作原理,git有一个缓存区,add就是添加到这个缓存区,并备注成first commit
~:git remote add origin git@github.com:hengha/hengha.git   #指定主仓库的地址
~:git push -u origin master       # push到GitHub的仓库上

3.
There are many ways to establish a connection between the key pair git and GitHub. The most convenient and safe way is to use the key pair. See the fifth picture in the GitHub section for details. When the key pair is used, it is easy to be executed when a new warehouse is created.

~:git remote add origin git@github.com:hengha/hengha.git
~:git push origin master

Report an error, this error is mainly due to the ssh secret key problem. My approach is to delete the ssh key before the GitHub warehouse. Follow the same steps to create a new Deploy key under the new warehouse. Of course, the git server key is not used. regenerate. After the operation is completed, the above command is executed, and it is successful.

三、Jenkins

In the use of this set of Jenkins, there are three places to pay attention to, one is jdk, the other is maven, and the last is the plug-in. It is recommended to install Jenkins on the same server as git.

Here, I have used the tar package downloaded from the source site, installed and deployed.
I’m not used to downloading from the official website. That’s how fast you want it to be, and how slow it is.

1. Jenkins download and installation
Suggestions go to:
Alibaba Cloud official mirror station: Alibaba Cloud official mirror station
Tsinghua University open source software mirror station: Tsinghua University open source software mirror station
https://mirrors.tuna.tsinghua.edu.cn/jenkins/war The
war package downloaded from /2.251/jenkins.war is dropped directly into tomcat's webapps directory, just restart tomcat, and Jenkins is installed. After restarting, it is recommended to delete the war package of Jenkins. Otherwise, restarting tomcat will decompress the war again and restore the configuration of Jenkins. You will have nowhere to cry.

2, jdk
install jdk to install version 1.8.0

~:yum -y install java-1.8.0
~: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)

The storage location is generally under /usr/lib/jvm/
jdk

3. Maven
people are under the eaves, how can they not bow their heads, go to the official website to download, or go to the official website to download.
Maven installation package
Create the installation path by yourself. After decompression, make a soft link to associate the decompressed mvn with the system default mvn.

ln -s /创建的路径/Maven/apache-maven-3.6.3/bin/mvn /usr/bin/mvn

The last is the setting of environment variables

~:vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
export MAVEN_HOME=/创建的路径/Maven/apache-maven-3.6.3/
export PATH=$MAVEN_HOME/bin:$PATH

4. Which plug-ins to install? When I
first entered Jenkins, there was a plug-in recommended to install. Click, which one will be used later, and which one is installed.
(1) The first plug-in is definitely going to make Jenkins the most possible Chinese. At first, you can identify its meaning based on the icon.
Find the Localization: Chinese (Simplified) plug-in installation in the plug-in management, and then restart it. The easiest and quickest way to restart is to add /restart after the URL bar.
(2) Maven plug-in is definitely indispensable, search for maven in the search bar
(3) Git related plug-ins, search git
(4) GitHub related plug-ins, search GitHub
(5) SSH connection plug-ins, search ssh
(6) Automated deployment requires an automated deployment plug-in, search deploy to container
( 7) There are also plug-ins with API interface.
As long as you use what you need, install it. If you find too many plug-ins, if you don't know what it means, install them all, saving trouble. It doesn't matter if you install too much, you can't run if you install less, right.

5. Global configuration
Manage Jenkins
Global configuration

Fourth, pack and go online

Now that everything is done, the next step is the time to test.
Go back to the Jenkins workbench and create a new task
New task
first slide
the second one
Third
Fourth
Fifth
Sixth

tomcat credential configuration


Configure tomcat account password in tomcat

~:cd conf/
~:vim tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-manager-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script"/>

The effect is shown in the figure below. After
tomcat
configuring, try to log in and get an error.

~:cd  webapps/magager/META-INF/
~:vim context.xml

Edit in the last part of the page, as shown in the figure below
tomcat
.
Go back to the built project page, click Build Now, and watch the console output. Seeing success means success.

to sum up:

1. The general idea of ​​this set is like this, first clear the idea, and then there will be more directions when you operate.
2. The use of Jenkins is also limited. It is best to choose the method that suits you according to your own business situation.
3. It may not be mentioned in some places. After checking the relevant information, the effect will be better when combined.

Guess you like

Origin blog.csdn.net/weixin_48226988/article/details/108225360