首先是安装步骤:
# 1、下载镜像仓库jenkins.repo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --no-check-certificate # 2、下载jenkins.io.key rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key # 3、yum下载安装依赖和jenkins yum install epel-release yum install java-11-openjdk-devel ##如果有装jdk8以上可跳过,我这里跳过 yum install jenkins # 4、设置配置文件端口号 vim /etc/sysconfig/jenkins #修改8080为自己想要的端口号 # 5、设置Jenkins账号的权限,否则启动可能报错 chown -R jenkins:jenkins /var/lib/jenkins chown -R jenkins:jenkins /var/log/jenkins chown -R jenkins:jenkins /var/cache/jenkins # 6、启动 systemctl start jenkins # 7、设置开机自启 systemctl enable jenkins # 8、访问 http://ip:port # 9、查看默认密码并登录 /var/lib/jenkins/secrets/initialAdminPassword
踩到两个坑:
①启动失败
原因为引用的jdk版本不符
vi /etc/init.d/jenkins
添加服务器安装的正确版本的jdk,之后重启依旧同样报错,所以重新建立 /usr/bin/java 软连接
ln -s /home/work/opt/jdk1.8.0_181/bin/java /usr/bin/java
启动成功。
②端口修改不生效
vim /etc/sysconfig/jenkins 修改 JENKINS_PORT="8089"
不生效
vim /usr/lib/firewalld/services/jenkins.xml 修改 port="8089"
依旧不生效
最后终于找到如下方法
vim /usr/lib/systemd/system/jenkins.service 修改 Environment="JENKINS_PORT=8089"
# 重新加载配置文件 systemctl daemon-reload
终于成功了