一、安装及启动Jenkins
方法一:配置jenkins yum源
可以在https://pkg.jenkins.io/网页中选择合适版本后,在网页上面可以看到:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
yum install jenkins -y
方法二:安装rpm包
在https://pkg.jenkins.io去查找适合自己操作系统的jenkins版本并下载
wget https://pkg.jenkins.io/redhat/jenkins-2.161-1.1.noarch.rpm
rpm -ivh jenkins-2.161-1.1.noarch.rpm
以上两种方法:
1、配置监听端口:
vim /etc/sysconfig/jenkins
JENKINS_PORT=“8080”
2、启动服务:
systemctl enable jenkins
尝试启动服务,发现有报错:
[root@localhost data]# systemctl start jenkins
Job for jenkins.service failed because the control process exited with error code. See “systemctl status jenkins.service” and “journalctl -xe” for details.
[root@localhost data]# systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2019-01-23 11:37:56 EST; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 1900 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)
Jan 23 11:37:56 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation Server…
Jan 23 11:37:56 localhost.localdomain runuser[1905]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Jan 23 11:37:56 localhost.localdomain jenkins[1900]: Starting Jenkins bash: /usr/bin/java: No such file or directory
Jan 23 11:37:56 localhost.localdomain jenkins[1900]: [FAILED]
Jan 23 11:37:56 localhost.localdomain systemd[1]: jenkins.service: control process exited, code=exited status=1
Jan 23 11:37:56 localhost.localdomain systemd[1]: Failed to start LSB: Jenkins Automation Server.
Jan 23 11:37:56 localhost.localdomain systemd[1]: Unit jenkins.service entered failed state.
Jan 23 11:37:56 localhost.localdomain systemd[1]: jenkins.service failed.
这里注意到其中的关键点:/usr/bin/java: No such file or directory
需要进行java环境变量的配置:
ln -s /usr/local/java/bin/java /usr/bin/java
再尝试启动jenkins:
systemctl start jenkins
ps aux|grep jenkins
方法三:安装war包
在网页找到合适版本的war包, http://mirrors.jenkins-ci.org/
wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
创建jenkins的家目录,并将war包放入。
mkdir /usr/local/jenkins
cp jenkins.war /usr/local/jenkins
export JENKINS_HOME=/usr/local/jenkins/
java -jar $JENKINS_ROOT/jenkins.war --httpPort=8080 &
//配置了从war包启动以及监听端口8080
注意按需将上面export内容写入/etc/profile
二、浏览器访问jenkins
http://10.0.0.200:8080
获取密码并登陆
cat /var/lib/jenkins/secrets/initialAdminPassword
参考文档 :
http://www.cnblogs.com/itech/p/3504722.html
https://www.cnblogs.com/stulzq/p/9291237.html