Jenkins 安装
强烈建议不要用docker安装jenkins,jenkins本身用docker安装不麻烦,但是安装那些插件太麻烦了
1.安装java(JDK1.8以上的java版本)
查找java相关的列表
yum -y list java*
安装:
yum install java-1.8.0-openjdk-devel.x86_64
配置环境变量:
vi /etc/profile
在文件最后加入:
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64 ##java安装目录,通过yum安装的默认路径为:/usr/lib/jvm
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
让修改生效:
source /etc/profile
测试:
java -version
看到版本号就成功了
2.安装jenkins
1.安装:
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
yum install jenkins
不要怀疑就是这么简单:官网 https://pkg.jenkins.io/redhat-stable/
启动:
/etc/init.d/jenkins start
查看状态:
systemctl status jenkins
发现端口是8080,其实这是默认端口,我们可以修改的端口
2.修改端口(也可能不改)
①端口修改不生效
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
再次查看状态
systemctl status jenkins
ps:如果没有改就重启一下
/etc/init.d/jenkins restart
问题1:
有时这就是单纯在 启动时超时了,重新启动就可以了
2.nginx反向代理jenkins
1.正常安装的nginx
server {
listen 80;
server_name jenkins.local.test; # 域名设置
location / {
proxy_pass http://127.0.0.1:8089;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
2.docker安装的nginx
server {
listen 80;
server_name jenkins.local.test; # 域名设置
location / {
proxy_pass http://172.22.0.1:8089; ## 172.22.0.1 是docker的默认网关
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
ps:查看docker默认网关
docker network ls
docker network inspect 8091c59ed73c