在centos7.5安装jenkins,内有修改默认端口为80,以及修改安装目录的步骤

本文详细介绍了如何在CentOS7.5上安装Jenkins,包括通过yum升级安装,启动Jenkins服务,配置IP地址,设置初始管理员密码,以及如何修改默认端口为80,并提供了更改Jenkins工作目录的步骤。

在centos7.5安装jenkins,jdk用的是openjdk1.8

install jenkins

前提:用普通用户Jenkins登录jenkins服务器,且普通用户具有sudo权限

  1. 在线下载 Jenkins

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

  1. 更新安装包

sudo yum upgrade

  1. 安装jenkins

sudo yum install jenkins

  1. 重新加载配置文件

sudo systemctl daemon-reload

Start Jenkins

  1. You can start the Jenkins service with the command:

sudo systemctl start jenkins

  1. You can check the status of the Jenkins service using the command:

sudo systemctl status jenkins

  1. config Jenkins

    • To configure Jenkins, you’ll need to find out your IP address. You can do that using the command.

    ifconfig -a

    • Now, open your preferred browser and enter your IP address in the search bar followed by a colon and the port number :8080 and you will be asked to enter a password.
    • To get the password, copy the following command and hit enter. Enter your Linux password if prompted.

    sudo cat /var/lib/jenkins/secrets/initialAdminPassword

    Copy the 32-digit value that appears and paste it in the panel.

    • Now, install the plugins and voila! You have successfully installed Jenkins.
    • Create First Admin user by entering the credentials you want to use and click Save and Finish.

  2. 如果输入http://your IP address:8080无法登录的话检查一下防火墙是否开放8080端口。
    (1)查看firewalld状态

sudo systemctl status firewalld

(2)如果防火墙是开启的状态检查8080端口是否开放(active (running) 即是开启状态)

sudo firewall-cmd --list-all

如果没有开放则需要开放8080端口

sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

命令含义:

–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
firewall-cmd --reload 并不中断用户连接,即不丢失状态信息

(3)另一种情况可能是8080端口被占用需要自行查找网上资料

  1. 如果你需要将jenkins默认端口8080改为80,可以有以下方法:
    将80端口重定向到8080端口(修改jenkins端口时出错,原因是因为1433以下的端口非root用户没有权限使用,故选择iptable重定向的方式)
    如果是修改默认端口为大于1433端口的情况直接编辑配置文件修改路径,然后确保端口未被占用以及端口处于开放状态(开放端口前面有写)
    注:先将jenkins停止运行
    sudo service jenkins stop
    (1)查看firewalld状态

sudo systemctl status firewalld

(2)若显示开启则关闭它,并禁止其开机启动

sudo systemctl stop firewalld
sudo systemctl disable firewalld.service

(3)安装iptables并设置开机启动

sudo yum install iptables-services

设置开机启动

sudo systemctl start iptables
sudo systemctl enable iptables.service

(4)查看防火墙规则

sudo iptables -L

(5)开放80,和8080端口

sudo iptables -I INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 8080 -m state --state NEW -j ACCEPT

查看防火墙规则是否生效

sudo iptables -L

(6)生效后保存添加的规则

sudo iptables-save > /etc/sysconfig/iptables

(7)将80端口重定向到8080端口

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

(8)保存

sudo service iptables save

(9)重启iptables

sudo systemctl restart iptables.service

注:如果不需要修改工作目录则可以开启jenkins并登录了!

sudo systemctl start jenkins

  1. 迁移工作目录(注意jenkins此时的状态是停止运行的
    (1)创建新的工作目录

sudo mkdir /inno/jenkins/jenkins_home

(2) 修改工作目录的用户和组避免权限不足

sudo chown -R jenkins:jenkins /inno/jenkins/jenkins_home

(3)修改/etc/sysconfig/jenkins文件中的JENKINS_HOME,JENKINS_USER

JENKINS_HOME="/var/lib/jenkins$NAME"默认是这个目录,改成自己的目录(/自己的目录 $NAME)
JENKINS_USER=" $NAME"

(4)转移JENKINS_HOME目录下的文件到新目录下

sudo cp -r /var/lib/jenkins/* /inno/jenkins/jenkins_home

(5) 启动jenkins

sudo service jenkins start

(6)登录(http://自己的地址:80)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值