1. 背景
在研发中,需要配置 CI/CD环境, jenkins 是很常用的持续集成工具。
2. 安装 jenkins
2.1 在 centos 下安装
代码语言:javascript复制sudo wget -O /etc/yum.repos.d/jenkins.repo
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum upgrade
sudo yum install jenkins java-1.8.0-openjdk-devel
sudo systemctl daemon-reload
2.2 启动
现在启动 Jenkins,可执行:
代码语言:javascript复制sudo systemctl start jenkins
检查启动状态
代码语言:javascript复制sudo systemctl status jenkins
处理防火墙
代码语言:javascript复制YOURPORT=8080
PERM="--permanent"
SERV="$PERM --service=jenkins"
firewall-cmd $PERM --new-service=jenkins
firewall-cmd $SERV --set-short="Jenkins ports"
firewall-cmd $SERV --set-description="Jenkins port exceptions"
firewall-cmd $SERV --add-port=$YOURPORT/tcp
firewall-cmd $PERM --add-service=jenkins
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload
注意:为jenkins 用户赋权才能正常使用
代码语言:javascript复制chown -R jenkins:jenkins /var/lib/jenkins
chown -R jenkins:jenkins /var/cache/jenkins
chown -R jenkins:jenkins /var/log/jenkins
systemctl restart jenkins
2.2 网页访问
打开 http://localhost:8080 即可访问
image.png
3. 配置 jenkins
查看初始密码
代码语言:javascript复制sudo cat /var/lib/jenkins/secrets/initialAdminPassword
获得初始密码后填入,会发现加载特别慢
国内的网络问题,我们来修改成国内的更新镜像更新地址
代码语言:javascript复制cd /var/lib/jenkins/
cat hudson.model.UpdateCenter.xml
cp hudson.model.UpdateCenter.xml hudson.model.UpdateCenter_bak.xml
vi hudson.model.UpdateCenter.xml
参考
- 官网 https://www.jenkins.io/doc/book/installing/linux/#red-hat-centos
- 启动后无法访问端口 https://blog.csdn.net/xiaoxiangzi520/article/details/90053475
- 修改成国内的更新镜像更新地址 https://www.cnblogs.com/shiyixirui/p/12887692.html
- jenkins 安装目录位置 https://www.cnblogs.com/zengjunhua/p/9375038.html
附录: jenkins 更新服务地址
代码语言:javascript复制http://mirror.xmission.com/jenkins/updates/update-center.json
http://updates.jenkins-ci.org/update-center.json
http://mirror.esuni.jp/jenkins/updates/update-center.json
jenkins 镜像查询地址: http://mirrors.jenkins-ci.org/status.html
jenkins 改成中文 https://blog.csdn.net/qq_38461773/article/details/107534358