tomcat部署Jenkins并配置jdk、maven、git

一、部署Jenkins

1、导入安装包

2、安装安装包

(1)、安装JDK和maven

创建jdk存储目录

# mkdir /usr/jdk64/

解压jdk到存储目录

# tar -zxvf jdk-8u191-linux-x64.tar.gz -C /usr/jdk64/

解压maven到指定目录

# tar -zxvf apache-maven-3.6.0-bin.tar.gz -C /usr/local/

配置jdk环境变量

# vi /etc/profile

在最后一行加入以下内容

export JAVA_HOME=/usr/jdk64/jdk1.8.0_191 
export MAVEN_HOME=/usr/local/apache-maven-3.6.0
export PATH
=$JAVA_HOME/bin:$MAVEN_HOME/bin

执行生效

# source /etc/profile

查看jdk版本

# java -version

查看maven版本

# mvn -v

[root@localhost ~]# mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /usr/local/apache-maven-3.6.1
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"

(2)、解压tomcat

# tar -zxvf apache-tomcat-7.0.92.tar.gz -C /home/

启动tomcat服务

# chmod +x /home/apache-tomcat-7.0.92/bin/*.sh

 # ./startup.sh 

 查看tomcat是否成功运行

http://192.168.100.117:8080/

把jenkins.war包放到tomcat服务器的webapps目录

# cp jenkins.war /home/apache-tomcat-7.0.92/webapps/

 

(3)启动Jenkins服务

http://192.168.100.117:8080/jenkins

查看密码

[root@localhost ~]# cat /root/.jenkins/secrets/initialAdminPassword
a2cdc1a392cb468fae850e6cafad34e8

 

(6)配置系统字符类型

单机“系统管理”按钮,面板出现字符类型报错,则需要手工修改软件的字符类型。修改tomcat编码方式,在server.xml中添加URIEncoding="UTF-8"字段,修改完成以后要重启tomcat服务器,黄色警告信息就会消除

 修改server.xml文件

# vi +71 /home/apache-tomcat-7.0.92/conf/server.xml 

connectionTimeout="20000"
URIEncoding="UTF-8"

修改完成重启tomcat服务器

# cd /home/apache-tomcat-7.0.92/bin/

# ./shutdown.sh 

# ./startup.sh 

二、配置Jenkins服务

重新登录Jenkins

1、新增JDK

单机“系统管理”-“Global Tool Configuration(全局工具配置)”-“新增JDK”

别名可以随便取,取消“自动安装”复选框,可以使用服务器本机的JDK,在“JAVA_HOME”文本框中输入绝对路径,完成后单击“save”

2、配置maven

3、安装maven插件

在进行新建项目,仍无法新建maven项目,在这里需要安装maven的服务插件。

单击“管理插件”,选择“可选插件”标签,在过滤处输入“maven”,选中“Maven Integration plugin”复选框,单击“直接安装”按钮

插件安装完之后重启Jenkins

4、配置本地git仓库

安装gitlab插件,系统管理–管理插件–可选插件

插件安装界面,会额外安装一些依赖关系的插件,jenkins基于ruby开发,所以会有ruby环境:

进入Jenkins服务器查看git客户端的版本

# git --version

[root@localhost ~]# git --version
git version 1.8.3.1

本地配置gitlab服务器域名

# vi /etc/hosts

添加内容:192.168.1.104 git.cnbisoft.com

[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.104 git.cnbisoft.com

生成秘钥

# ssh-keygen -t rsa -C "djl@cnbisoft.com"

[root@localhost ~]# ssh-keygen -t rsa -C "djl@cnbisoft.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:gC8otLSTT5RR3D1up6OXn9gK5vq8GJz6GbTO2cdgnLs djl@cnbisoft.com
The key's randomart image is:
+---[RSA 2048]----+
|   .o.. .        |
|    oo . o       |
| o o. . . .      |
|o =. . . o .     |
|.=....o S o      |
| .+ o.o= o       |
|   . *.o= o      |
|    + @o.=o .    |
|   ..OoE=oo+     |
+----[SHA256]-----+

登陆gitlab

在gitlab上添加ssh秘钥,这要添加的是“id_rsa.pub”即“公钥”

 

在Jenkins服务器上查看公钥密文

# cat .ssh/id_rsa.pub

[root@localhost ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8088vsVidvaGCaUjDQg5SskdPC6zMChUMVCp20nl+GPa8RpdaNXYviw+bzLu57Uy05VK29J5L47cjuVjTDAzUUZJfE4cApXvhDzPM/25eaKZSyK6WCmm31eS5O3GnLn940QpQn5neSi3jUye2r1O8vB9KJb/hZCfaD/+pm8txeGujHzRbsbDRsME03wJi/h4IsmRQST4+4uOGwzXPXnEYYonziQladMn17a9yzgvIxzf0pLzdMFF4B049suCsGqEQdfh15TRvC+KTFjJ77K10R5h8OW58QiE0fJji9ci42CwNbBC9UVJOSKABCXu3aCD4ohi43ctMw4mrN57+PwSJ djl@cnbisoft.com

把公钥密文添加到如下页面:

添加后效果:

测试连接

输入主机名测试

# ssh git@git.cnbisoft.com

未配置主机名也可以使用IP地址测试

# ssh git@git.cnbisoft.com

# ssh git@192.168.1.104

[root@localhost ~]# ssh git@git.cnbisoft.com
The authenticity of host 'git.cnbisoft.com (192.168.1.104)' can't be established.
ECDSA key fingerprint is SHA256:7N9TpOaQok0LX5EuSjfmD3j2A6FIvHc59mKNK4tyFXs.
ECDSA key fingerprint is MD5:4a:fb:2e:d8:53:7d:f1:5a:1a:5d:17:12:d5:a1:81:6f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git.cnbisoft.com,192.168.1.104' (ECDSA) to the list of known hosts.
PTY allocation request failed on channel 0
Welcome to GitLab, 杜家利!
Connection to git.cnbisoft.com closed.
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# ssh git@192.168.1.104
PTY allocation request failed on channel 0
Welcome to GitLab, 杜家利!
Connection to 192.168.1.104 closed.
[root@localhost ~]#

拉取文件测试

# git clone --recursive git@git.cnbisoft.com:cnbigjx/cloud-platform.git

[root@localhost ~]# cd /home/
[root@localhost home]#
[root@localhost home]# ls
[root@localhost home]#
[root@localhost home]# git clone --recursive git@git.cnbisoft.com:cnbigjx/cloud-platform.git
Cloning into 'cloud-platform'...
remote: Counting objects: 18944, done.
remote: Compressing objects: 100% (684/684), done.
remote: Total 18944 (delta 457), reused 0 (delta 0)
Receiving objects: 100% (18944/18944), 10.94 MiB | 10.31 MiB/s, done.
Resolving deltas: 100% (14202/14202), done.
[root@localhost home]#
[root@localhost home]# ls
cloud-platform
[root@localhost home]#

配置Jenkins凭证

复制jenkins拉取git代码服务器root的私钥

# cat .ssh/id_rsa

[root@localhost ~]# cat .ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAuFlwi31N+m0LoN9Tm+uUFGkSQiYYr5WB7gx5T357QH9wQwhL
U6YgcxoCjk4PmZlgMh88gNFvPgSkhgWIlsmMQX5odzySw3OhsOcvkREbtvvV5yiM
k/4EEP3EO44gOFWhk2JCtBIv9B37AgfiNr64X0j7KK9M730HAzuXyP9EJ6Dix/Q5
6Sz0k+d5YtvCt42oJSBQaC/Ix+3FwA9DbWxlZfUe7yOex0TNAYtH6HxubC2hdhaq
1CQHOdHdgGyKa6b+8QHQgo5rx4zbGYHj9CVlQvzCajaguAaY0KtIXkGRuMwrz4Ym
IX2B6fGbj9TjecJgdNuJ6upb271rF45ZtbSCjwIDAQABAoIBAQCh76cmURcLkXhy
g1rtjz4Pw9CPHOn4ayusUXbKtr9MA+Y4a/PHchn1Ifb2zGl1sr5GqRu7yL2gS/G9
7OR0GG3FJmZbv3Dokg2J2Tr2goHG9meK3BrI8Yze5BvZeNqiwc3iKqGPjp5jIWbZ
/NTg5B4PTYuazIqXoUtkspd9r4ZOC8z5DtljLcZx2M8p5hvCTcM2CmHzpKuIWd2W
aJN4cGkDDiZLtGdKZqFR0M/d2gH+Sq9bUMbjrZr+FD9dwrXsWGNilMt/3JzIxr5u
ARvSLDtl8y6QSfGr2Xd/eXBOQmB6ZMyZOZYEnSsfTJvURGWQVW5N6E7Paku/9m2N
t1nTxalRAoGBAPGWjDv7BZzXy7KojhlmfQlCecQvVLcJOtBT1xBdkekWjP/LtojI
5GzlUYZeDpMQ5k6ifS1cPqES66UQHVMSbdtHbf+Bdianou91zwLGJjkSdaVDPAiF
MLpjw07yFqhcjgoy1MgIqJehtq8wlWkKKAOpOavwYlHl7o+ciSFZGkQHAoGBAMNY
wvMzL4fwsPRM3GyX38GqOflKIQImVvi/bG/fU13NhLDlwRdVQTMsSFWL3I/DcDWW
rob113fzGNY68nF37DuBqWs2lvrTPlRVHKFxIEEqG8GLmYQKvx8pqU5WE7/IjZeF
FpS5uxWsHJ4YTVb9zK4YcJaoM8HbpqRtlRzrdHs5AoGAC3BEXYaqIl35UBE5ASzg
GLMkDszq5uux9DE0CptTkES4Elhz4RAZ+Kn27TTA3ee779cztBUdBgVeUOdtbASA
XRSJucJIdNYVGd9rGMeHAcbE+Tkwu3qK7xhQJAnEVt5i/0qe1oXKbbuDadIUEPAh
KuM1TtXH4fbQD86qk4CjhLsCgYAuuDnX5HQHtR79LqzBJAmVzdqTrpD6bKT8VPvg
Pa84jgCgNjLaG7++N2cNXqffkkRx7JnNGVrxCyjzg6GcVawgB0C3rZSqZH9RuBFi
4yVtsF53CaYrmE5ha5tcauXKRnLmvCPMaic+Za1qejF1Dro3IQ08WvoV8SyHwtWY
1w9CsQKBgEcdE+KGtYn57v3QqeR3OrAwF7PnRR2NA80dhyuRyY3CjoQDYDQ8oK4d
XPT0eGa8f40mLKjVbFoYkeJ+cgraPtCrtGYYgTNuSErwf+SXXce6e4bBqeuncf82
XsqyHOjO71pdU6mk66jq51ywfGrV4O/TLrY8zKG5nvg1qrksHVNo
-----END RSA PRIVATE KEY-----

 

参考博客:https://www.cnblogs.com/reblue520/p/7130914.html

5、安装容器部署插件

在过滤处输入“deploy”,选择“Deploy to container Plugin”复选框,单击“直接安装”

安装完成后重启Jenkins

 end

posted on 2019-01-18 14:01  阿小杜  阅读(2887)  评论(0编辑  收藏  举报