一、安装和安装Jenkins
0.前提
- 因jenkins从2.357版本开始不再支持java8
2、jenkins与java版本对应查看,与jenkins下载:Redhat Jenkins Packages
3、打算使用java8,所以选择安装2.346.3-1.1
4、安装jenkins之前,安装好java8并配置好环境变量。
1、下载Jenkins
$wget https://mirrors.aliyun.com/jenkins/redhat-stable/jenkins-2.346.3-1.1.noarch.rpm
$wget https://get.jenkins.io/redhat-stable/jenkins-2.346.3-1.1.noarch.rpm --no-check-certificate
2、安装Jenkins
$yum install -y jenkins-2.346.3-1.1.noarch.rpm
3、设置开机自启
$systemctl enable jenkins
Created symlink from /etc/systemd/system/multi-user.target.wants/jenkins.service to /usr/lib/systemd/system/jenkins.service.
4、启动Jenkins
$systemctl start jenkins
执行journalctl -xe查看已经启动成功,并查看到初始密码
二、配置Jenkins
1、访问jenkins,并设置管理员账号和密码
访问:http://ip:8080
输入密码,通过命令查到的密码
$cat /var/lib/jenkins/secrets/initialAdminPassword
214c01c62b4da4048a96782c9b65090c5
2、安装插件和配置用户等
三、其他:Jenkins其他可选项
1、查看安装后生成的目录
/var/cache/jenkins
/var/lib/jenkins/
/var/log/jenkins
2、配置jenkins(如要配置端口)
#3.1修改配置:vim /etc/sysconfig/jenkins
修改时区:JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dorg.apache.commons.jelly.tags.fmt.timeZone=Asia/Shanghai"
将默认配置:
JENKINS_USER=”jenkins”
JENKINS_PORT=”8080”
修改为:
JENKINS_USER=”root”
JENKINS_PORT=”8888”
3、启动Jenkins的一些命令
# 查看状态:sudo systemctl status jenkins
# 启动服务:sudo systemctl start jenkins
# 重启服务:sudo systemctl restart jenkins
4、防火墙端口设置的一些命令
sudo systemctl status firewalld
sudo systemctl stop firewalld
sudo systemctl disable firewalld
或
firewall-cmd —zone=public —add-port=8888/tcp —permanent
firewall-cmd —reload
5、#查看是否自启动
systemctl is-enabled jenkins
6、#查询端口
netstat -lntp |grep 8080
7、其他使用以下方法启动jenkins
cd /etc/init.d # 启动 ./jenkins start # 停止 ./jenkins stop # 状态 ./jenkins status |
#查看原始密码
$cat /var/lib/jenkins/secrets/initialAdminPassword
14c01c62b4da4048a96782c9b65090c5
8、卸载过程
1)sudo rpm -e jenkins #rpm卸载Jenkins
2)sudo rpm -ql jenkins #查看是否卸载成功
3)sudo find / -iname jenkins | xargs -n 1000 rm -rf #彻底删除残留文件(这个估计要root的用户)