1.从官网下载最新版本的tomcat
下载地址:https://tomcat.apache.org/
2.Jenkins 官方网站下载最新版本war包
Jenkins官网地址:http://jenkins-ci.org/
3.安装Jenkins
步骤一、将jenkins的war包拷贝到 $TOMCAT_HOME/webapps 下(不用解压),删除 webapps 下其他目录
步骤二、创建存放jenkins数据的目录,并添加环境变量,命令如下:
mkdir /jenkins vi /etc/profile 添加 export JENKINS_HOME=/jenkins
步骤三、写启动jenkins服务脚本,命令如下:
vi /etc/init.d/jenkins
添加如下内容,如果你希望用指定用户启动,请修改 JENKINS_USER=root 的值,但要记得更改 /jenkins 以及Tomcat 目录的访问权限。另外其他环境变量例如 JAVA_HOME 和 TOMCAT_HOME 要根据你实际JDK和Tomcat的安装目录修改。
#!/bin/sh # # Startup script for the Jenkins Continuous Integration server # (via Jakarta Tomcat Java Servlets and JSP server) # # chkconfig: - 85 15 # description: Jakarta Tomcat Java Servlets and JSP server # processname: tomcat # pidfile: /var/run/tomcat.pid # Set Tomcat environment. JENKINS_USER=root LOCKFILE=/var/lock/jenkins export PATH=/usr/local/bin:$PATH export HOME=/jenkins export JAVA_HOME=/opt/jdk1.8.0_161 export JENKINS_BASEDIR=/jenkins export TOMCAT_HOME=/opt/apache-tomcat-9.0.8 export CATALINA_PID=$JENKINS_BASEDIR/jenkins-tomcat.pid export CATALINA_OPTS="-DJENKINS_HOME=$JENKINS_BASEDIR/jenkins-home -Xmx512m -Djava.awt.headless=true" [ -f $TOMCAT_HOME/bin/catalina.sh ] || exit 0 export PATH=$PATH:/usr/bin:/usr/local/bin # See how we were called. case "$1" in start) # Start daemon. echo -n "Starting Tomcat: " su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh start" RETVAL=$? echo [ $RETVAL = 0 ] && touch $LOCKFILE ;; stop) # Stop daemons. echo -n "Shutting down Tomcat: " su -p -s /bin/sh $JENKINS_USER -c "$TOMCAT_HOME/bin/catalina.sh stop" RETVAL=$? echo [ $RETVAL = 0 ] && rm -f $LOCKFILE ;; restart) $0 stop $0 start ;; condrestart) [ -e $LOCKFILE ] && $0 restart ;; status) status tomcat ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0
步骤四、赋予启动脚本可执行权限,并设置开机启动,命令如下:
chmod a+x /etc/init.d/jenkins chkconfig jenkins on service jenkins start
步骤五、http://192.168.1.171:8080/jenkins/ 可以看到 Jenkins 已经启动了
布置 Nginx 做一下反向代理
步骤一、下载并安装nginx
步骤二、编辑nginx启动文件,命令如下:
vi /etc/nginx/nginx.conf
修改成如下内容
user root; worker_processes auto; error_log /var/log/nginx/error.log error; events { worker_connections 10240; } http{ server { listen 80; server_name ci.abc.com; client_max_body_size 60M; client_body_buffer_size 512k; location / { proxy_pass http://localhost:8080; 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; } } }
启动nginx service nginx start
步骤三、修改本机hosts文件(C:WindowsSystem32driversetchosts)
192.168.1.171 ci.abc.com
步骤四、访问
这次我们在浏览器里输入 http://ci.abc.com/jenkins 可以看到页面了!