导读 | Jenkins是一个开源的Java Web项目,一个持续集成的Web项目。例如在自动化测试中,开发了自动化测试的,不可能一直用IDE来运行,然后查看测试结果,这个时候我们就需要借助一个平台,可以自动获取最新代码,编译并构建,并且是在设置的时间持续执行,自动化完成这些步骤以后并把测试的结果以邮件的形式发送给指定的开发,测试人员,这是Jenkins在自动化测试上的主要用途。 |
1.从官网下载最新版本的tomcat
下载地址://tomcat.apache.org/
2.Jenkins 官方网站下载最新版本war包
Jenkins官网地址://jenkins-ci.org/
3.安装Jenkins
将jenkins的war包拷贝到 $TOMCAT_HOME/webapps 下(不用解压),删除 webapps 下其他目录
创建存放jenkins数据的目录,并添加环境变量,如下:
mkdir /jenkins vi /etc/profile 添加 export JENKINS_HOME=/jenkins
写启动jenkins服务,如下:
#!/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
//192.168.1.171:8080/jenkins/ 可以看到 Jenkins 已经启动了
下载并安装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 //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:\Windows\System32\drivers\etc\hosts)
192.168.1.171 ci.abc.com
最后我们在浏览器里输入 //ci.abc.com/jenkins 可以看到页面了!
原文来自:
本文地址://gulass.cn/tomcat-deploys-jenkins.html编辑:KSJXAXOAS,审核员:逄增宝
Linux命令大全:
Linux系统大全: