Jenkins 安装
Posted jameslove
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jenkins 安装相关的知识,希望对你有一定的参考价值。
系统:Centos7.4
环境:jdk1.8.151, tomcat8.5.37,jenkins2.157
1,安装Jenkins
[[email protected] ~]# systemctl stop firewalld 先关闭防火墙
[[email protected] ~]#wget http://updates.jenkins-ci.org/download/war/2.157/jenkins.war
[[email protected] ~]#wget http://mirror-hk.koddos.net/apache/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
[[email protected] ~]# ll
总用量 83656
-rw-------. 1 root root 1257 2月 28 19:07 anaconda-ks.cfg
-rw-r--r--. 1 root root 9653382 12月 12 21:00 apache-tomcat-8.5.37.tar.gz
-rw-r--r--. 1 root root 76001412 1月 7 06:mkdir /data/app -p45 jenkins.war
[[email protected] ~]# mkdir /data/app -p
[[email protected] ~]# tar xf jdk-8u151-linux-x64.tar.gz -C /data/app/
[[email protected] ~]# mv /data/app/jdk1.8.0_151 /data/app/jdk
[[email protected] ~]# vim /etc/profile
export JAVA_HOME=/data/app/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
PATH=${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] ~]# . /etc/profile
[[email protected] ~]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
[[email protected] ~]# tar xf apache-tomcat-8.5.37.tar.gz -C /data/app/
[[email protected] ~]# mv /data/app/apache-tomcat-8.5.37 /data/app/jenkins
[[email protected] ~]# rm -rf /data/app/jenkins/webapps/*
[[email protected] ~]# cp -rp jenkins.war /data/app/jenkins/webapps/
[[email protected] ~]# /data/app/jenkins/bin/startup.sh
Using CATALINA_BASE: /data/app/jenkins Using CATALINA_HOME: /data/app/jenkins Using CATALINA_TMPDIR: /data/app/jenkins/temp
Using JRE_HOME: /data/app/jdk/jre Using CLASSPATH: /data/app/jenkins/bin/bootstrap.jar:/data/app/jenkins/bin/tomcat-juli.jar Tomcat started.
[[email protected] ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1002/sshd
tcp6 0 0 :::8009 :::* LISTEN 41146/java
tcp6 0 0 :::8080 :::* LISTEN 41146/java
tcp6 0 0 :::22 :::* LISTEN 1002/sshd
Jenkins 启动完成, 开始 jenkins 图形界面的配置:
[[email protected] ~]# cat /root/.jenkins/secrets/initialAdminPassword
2696147a4c2b44c3b1cf42dfe5a290aa 这就是初始化Admin 密码
输入初始化 Admin 密码:
?
Install suggested plugins: 安装建议的插件
?
会自动安装一些建议的插件
?
安装好之后,会让你手动创建一个管理员账号:
?
?
?
点击Start using jenkins,开始使用 jenkins。
注意:jenkins 的不同版本,安装过程可能会有点差异。此版本是 jenkins 最新版本。
开始登陆 jenkins
?
输入刚刚新建的管理员账号密码登陆。(如果输入账号密码,点击登陆,出现空白页面, 请重启 jenkins 程序,再尝试登陆。)
?
2.配置Jenkins
2.1配置环境(安装ssh插件,配置ssh插件)
实现目标:通过Jenkins这台服务器。可以ssh远程到其他的任意节点服务器,执行脚本或者命令。
[[email protected] ~]# ssh-keygen -t rsa
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:zlXWGMoy3pA/878k1BlzQ00rI/2cQRj1hCVhMnSt1e4 [email protected] The key‘s randomart image is: +---[RSA 2048]----+
| .=.OX*|
| o ..X+oB|
| = o.+++Bo|
| . * o..*==|
| S * . o= |
| o . = E|
| o o . |
| + |
| o. | +----[SHA256]-----+
[[email protected] ~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VXipdima03pqw2/g758YfNtyvBqjAoGANP57roLHQ+zZ3xCiotZq
HuZi7da3AxGqBoTca4fFS80vlN2RIFOO7n8K+nAMSJUfO4y8ZxLcuXAVUBHFHmy0
nLWtwVgacNLKfJDuDKRudmMh4pRMsZ9tp6jhfDy5mRD9/aTB4vwk9ZT2EGBykhSE
FGI1iYOyn34cgKK7ymemsZkCgYBwuPW6K2BrCjGgzhMdu282MJwjcz2/m8fgwSoH
M25e4PjKzSzvX9AQPNPR0MG3gW+iHLqFLCb4fPqlpNbuQXecSdv0ZwtaLYNqtpen
JdF6uhznbRK9Q8HeaCtTW54tFVvU+bEd+yPWVCHyXw6w+ggT18SM6vYg/4FiytQi
7ZFV2QKBgQCmmDR2MBgGVu0DPA5+XzumnfO2A5hgeLz2lN5jHD0JnsZHvD64TGFE
JzvnMLJWY48w2x+1LKI8rIbAOf5Kc2bVU4QQn8kaQe/5mV6byXkc+2Ucg1OBVZjb
pT5NwVmulQeWAGqMvTxUBwvdx+a+3dPRZev02hfvCVN5J4qTKlRmwA==
-----END RSA PRIVATE KEY-----类型:ssh 用户名的私钥?
username: root 用户
Private key:私钥
描述:jenkins(privite_key)
2.2 在 jenkins 服务上,通过 ssh-copy-id 对其他几点进行免秘钥配置.
??
面秘钥配置完成 可以正常登陆
3. 安装 ssh 插件并配置 ssh
系统管理--插件管理--搜索 ssh
?
?
配置ssh,系统管理--系统设置
?
配置 ssh remote hosts
?
点击新增
?
Hostname: 节点 ip
Port: 22
Credentials: jenkins 凭据
配置 publish over ssh
?
Name: 可以随意填写
Hostname: 节点 ip
Username: root
Remote directory: /
配置好之后,在最下方点击保存即可。
2.3 Demo 实例
需求:使用 jenkins 在 192.168.174.157节点服务器上运行脚本 /data/app/sh/test.sh
建议:可以先新建一个视图,所有任务都放在视图里面
我的视图新建视图
?
进入视图后,填写名称。点击保存
?
点击demo,点击创建新的任务
?
?Jenins 这台机器会通过 ssh 去连接 192.168.174.157 这台机器,然后在执行 cd /data/app/sh && sh -x test.sh 命令。
以上是 jenkins 基本的配置
以上是关于Jenkins 安装的主要内容,如果未能解决你的问题,请参考以下文章
[Jenkins01] Jenkins的安装和部署(jenkins教程)