一、安装JDK
1.解压jdk的tar包
$ tar zxvf jdk-8u181-linux-x64.tar.gz -C /usr/local/
2.创建软连接
$ ln -sv /usr/local/jdk1.8.0_181/ /usr/local/java
3.添加环境变量
$ vim /etc/profile.d/java.sh
JAVA_HOME=/usr/local/java
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
4.执行环境变量文件
$ source /etc/profile.d/java.sh
5.检查JDK版本
$ java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
二、安装Tomcat
1.解压tomcat
$ tar zxvf apache-tomcat-9.0.12.tar.gz -C /usr/local
2.创建软连接
$ ln -sv /usr/local/apache-tomcat-9.0.12/ /usr/local/tomcat
3.修改tomcat绑定的IP地址
$ cd /usr/local/tomcat
$ vim ./conf/server.xml
<Connector port="8080" address="192.168.101.100" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
4.启动tomcat
$ ./bin/catalina.sh start
$ ss -tunl | grep -E "8080|8009|8005"
tcp LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
tcp LISTEN 0 100 :::8009 :::*
tcp LISTEN 0 100 ::ffff:192.168.101.100:8080 :::*
5.curl测试
$ curl -I http://192.168.101.100:8080
HTTP/1.1 200
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 17 Sep 2018 13:31:56 GMT
三、安装jenkins
1.关闭tomcat
$ ./bin/catalina.sh stop
2.备份webapps
$ cp -a -rf ./webapps ./webapps-bak
3.删除webapps目录种内容
$ rm -rf ./webapps/*
4.将jenkins.war放入webapps, 并修改为ROOT.war
$ mv webapps/jenkins.war webapps/ROOT.war
5.设置jenkins home
$ mkdir /usr/local/jenkins
$ vim /etc/profile.d/jenkins.sh
export CATALINA_OPTS="-DJENKINS_HOME=/usr/local/jenkins/ -Xmx512m"
$ source /etc/profile.d/jenkins.sh
$ echo $CATALINA_OPTS
-DJENKINS_HOME=/usr/local/jenkins/ -Xmx512m
6.重新启动tomcat
$ ./bin/catalina.sh start
7.浏览器打开192.168.101.100:8080, 初始化jenkins
四、安装nginx
1.安装nginx
$ yum install -y nginx
2.制作TLS证书
3.修改nginx配置文件
upstream jenkins {
server 192.168.101.100:8080 fail_timeout=0;
}
server {
listen 443 ssl;
server_name rancher.leistudy.com;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http:// https://;
proxy_pass http://jenkins;
proxy_http_version 1.1;
proxy_request_buffering off;
#add_header 'X-SSH-Endpoint' 'rancher.leistudy.com:22' always;
}
}
4.检查nginx配置并启动
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ systemctl start nginx
$ ss -tunl | grep "443"
tcp LISTEN 0 128 *:443 *:*
5.登陆https://192.168.101.100查看
五、参考文档
https://wiki.jenkins.io/display/JENKINS/Tomcat
https://wiki.jenkins.io/display/JENKINS/Jenkins+behind+an+NGinX+reverse+proxy
转载于:https://blog.51cto.com/13501622/2176387