在开发上线的过程中,遇到几个痛点问题
1. Web端生产环境上线,每次都需要手动打包,然后用ftp的方式上传。
2. 服务端生产环境上线,打的包体积较大,用ftp的方式上传,服务会停掉一段时间。
既然 ftp的方式不适用了,那就上持续集成吧,这里使用的是Jenkins工具
Part1 Jenkins的安装
环境说明
推荐的硬件配置: 1 GB的RAM,50 GB的驱动器空间
系统环境
cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
uname -r
3.10.0-957.21.3.el7.x86_64
systemctl status firewalld 或者 firewall-cmd --state 查看防火墙状态
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2019-10-29 17:37:35 CST; 1 months 0 days ago
软件要求
Java 8
不支持在centos的默认的jdk上工作。如果如下所示,需要remove掉
java -version
java version "1.5.0"
gij (GNU libgcj) version 4.4.6 20110731 (Red Hat 4.4.6-3)
为了正确使用Jenkins
yum remove java
可以安装openjdk
yum install java-1.8.0-openjdk
正确输出如下
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
修改配置
配置文件位置 /etc/sysconfig/jenkins
JENKINS_PORT="12138"
直接启动
sudo service jenkins start
若是发现启动失败,尝试配置java路径,将你的Java地址加到 candidates 列表里,然后重新启动。
vim /etc/init.d/jenkins
# Set up environment accordingly to the configuration settings
[ -n "$JENKINS_HOME" ] || { echo "JENKINS_HOME not configured in $JENKINS_CONFIG";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
[ -d "$JENKINS_HOME" ] || { echo "JENKINS_HOME directory does not exist: $JENKINS_HOME";
if [ "$1" = "stop" ]; then exit 0;
else exit 1; fi; }
# Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins.
# see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-11.0/bin/java
/usr/lib/jvm/jre-11.0/bin/java
/usr/lib/jvm/java-11-openjdk-amd64
/usr/bin/java
"
1. 根据提示路径查看初始密码,并输入
cat /root/.jenkins/secrets/initialAdminPassword
2. 安装插件
若无特殊需要,选择第一个,安装推荐插件 即可
安装失败的插件,进入界面后,去插件管理手动安装即可
3.设置账号密码,进入Jenkins工具