简单介绍下如何安装配置Jenkins,以及如何快速迁移/复制整个Jenkins到其他服务器
- 下载Jenkins的官方rpm包
wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.263.1-1.1.noarch.rpm
- 安装Jenkins
rpm -ivh jenkins-2.263.1-1.1.noarch.rpm
- 简单配置Jenkins
#备份原始配置
cp /etc/sysconfig/jenkins /etc/sysconfig/jenkins.bk
#更改Jenkins的启动用户,默认为jenkins用户
sed -ri 's#JENKINS_USER="jenkins"#JENKINS_USER="root"#g' /etc/sysconfig/jenkins
#更改Jenkins启动端口,默认为8080
sed -ri 's#JENKINS_PORT="8080"#JENKINS_PORT="18080"#g' /etc/sysconfig/jenkins
#添加自定义JDK路径
echo $JAVA_HOME
java_path="${JAVA_HOME}/jre/bin/java"
sed -i "/candidates=/a\\${java_path}" /etc/init.d/jenkins
- 启动Jenkins
systemctl daemon-reload
systemctl start jenkins
# Jenkins的url为
http://xx.xx.xx.xx:18080/
- 如果需要迁移到其他服务器,以下为迁移的步骤
#在老的服务器,整个打包Jenkins目录
cd /var/lib/
tar /tmp/jenkins_full_v1.tgz jenkins
#在新的服务器,重复执行步骤1/2/3安装Jenkins(此步骤主要是为了在新的服务器把service之类的安装好)
#之后把老的服务器备份
mv /var/lib/jenkins/ /var/lib/jenkins_bk
#然后把老服务器打包的jenkins_full_v1.tgz包解压
tar -zxvf jenkins_full_v1.tgz -C /var/lib/
#新的服务器启动Jenkins
systemctl daemon-reload
systemctl start jenkins