gitlab之实战部署
#:准备Java环境,安装jdk root@ubuntu:~# cd /usr/local/src/ root@ubuntu:/usr/local/src# ls jdk-8u191-linux-x64.tar.gz root@ubuntu:/usr/local# ln -sv /usr/local/src/jdk1.8.0_191 /usr/local/jdk
#:配置环境变量
root@ubuntu:/data/tomcat# vim /etc/profile
export JAVA_HOME=/usr/local/jdk
export TOMCAT_HOME=/apps/tomcat
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$TOMCAT_HOME/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
#:创建目录,并下载Tomcat
root@ubuntu:/data/tomcat# mkdir /apps
root@ubuntu:/data/tomcat# cd /apps/
root@ubuntu:/data/tomcat# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.46/bin/apache-tomcat-8.5.46.tar.gz
root@ubuntu:/data/tomcat# tar xf apache-tomcat-8.5.46.tar.gz
root@ubuntu:/data/tomcat# ln -sv /apps/apache-tomcat-8.5.46 /apps/tomcat
root@ubuntu:/data/tomcat# cd tomcat
#:修改Tomcat配置文件
root@ubuntu:/data/tomcat# vim conf/server.xml
<Host name="localhost" appBase="/data/tomcat/tomcat_webapps" unpackWARs="true" autoDeploy="true">
#:创建三个目录(appdir放压缩文件,webdir放解压文件,webapps是Tomcat的访问/目录)
root@ubuntu:/data/tomcat# mkdir /data/tomcat/{tomcat_appdir,tomcat_webdir,tomcat_webapps} -pv
#:创建一个Tomcat用户(必须使其可以登录)
root@ubuntu:/data/tomcat# groupadd -g 2019 tomcat
root@ubuntu:/data/tomcat# useradd -m -u 2019 -s /bin/bash -g tomcat tomcat
#:编辑一个Tomcat的启动停止脚本
root@ubuntu:~# vim tomcat
#!/bin/bash
JDK_HOME=/apps/jdk1.7.0_79
CATALINA_HOME=/apps/tomcat
export JDK_HOME CATALINA_HOME
source /etc/profile
#PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'`
#NUM=`ps -ef | grep -v grep | grep java | awk '{print $2}' | wc -l`
#case $1 in
start() {
echo "正在判断服务状态,请稍等!"
echo "请稍等3秒钟"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
echo "Tomcat已经正在运行了!"
else
echo "Tomcat没有运行,1秒后启动!"
echo 1;sleep 1
$CATALINA_HOME/bin/catalina.sh start
echo "Tomcat 已经成功启动完成,5秒后判断是否启动成功"
echo "5";sleep 1;echo "4";sleep 1
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
PID=`ps -ef | grep tomcat | grep jdk | awk '{print $2}'`
NUM=`ps -ef | grep tomcat | grep jdk | awk '{print $2}' | wc -l`
echo "Tomcat 已经成功启动${NUM} 个Tomcat进程!,PID为${PID}"
else
echo "Tomcat启动失败,请重新启动!"
echo 1
fi
fi
}
stop() {
PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'`
NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l`
echo "正在判断服务状态,请稍等3秒钟!"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
echo "Tomcat运行中,1秒后关闭!"
echo 1;sleep 1
echo "即将关闭Tomcat服务,请稍等!"
$CATALINA_HOME/bin/catalina.sh stop ;echo "已经执行关闭命令,正在检查关闭了多少Tomcat进程,请稍等30秒钟!"
sleep 27
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
pkill java && pkill tomcat
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'`
NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l`
kill -9 $PID ;echo "已成功关闭${NUM} 个tomcat进程"
else
echo "Tomcat 已经关闭完成!"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
fi
else
echo "Tomcat 没有运行"
echo 1
fi
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'`
#NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l`
echo "关闭失败,即将强制删除tomcat进程!"
sleep 2
pkill tomcat ;sleep 2
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
echo "强制关闭失败,即将再次强制删除tomcat进程!"
pkill java; sleep 2
fi
fi
}
#:切换到tomcat,利用脚本启动服务
root@ubuntu:~# su -tomcat
tomcat@ubuntu:~$ /etc/init.d/tomcat start
#:配置keepalive+haproxy
#:安装
root@ubuntu:~# apt install haproxy keepalived -y
#:配置haproxy
root@ubuntu:~# vim /etc/haproxy/haproxy.cfg
global
maxconn 100000
#chroot /usr/local/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /run/haproxy.pid
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /haproxy-status
stats auth haadmin:q1w2e3r4ys
listen web_port
bind 0.0.0.0:80
mode http
log global
server 192.168.6.104 192.168.6.104:8080 check inter 3000 fall 2 rise 5
server 192.168.6.103 192.168.6.103:8080 check inter 3000 fall 2 rise 5
#:查找keepalive的配置文件在哪里
root@ubuntu:~# find / -name keepalived*.conf*
#:将配置文件拷贝到、etc目录
root@ubuntu:~# cp /usr/share/doc/keepalived/samples/keepalived.conf.vrrp /etc/keepalived/keepalived.conf
#:修改配置文件
root@ubuntu:~# vim /etc/keepalived/keepalived.conf
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
garp_master_delay 10
smtp_alert
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.6.200 dev eth0 label eth0:0
}
}
#:修改内核参数
root@ubuntu:~# vim /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
#:重启服务
root@ubuntu:~# systemctl restart haproxy keepalived
#:在jenkins服务器,将公钥拷贝到Tomcat服务器 root@ubuntu:/opt/web1# ssh-copy-id tomcat@192.168.6.104
#:怎样部署war包的jenkins #:先部署jdk root@ubuntu:~# cd /usr/local/src/ root@ubuntu:/usr/local/src# tar xf jdk-8u191-linux-x64.tar.gz root@ubuntu:/usr/local/src# ln -sv /usr/local/src/jdk jdk1.8.0_191/ jdk-8u191-linux-x64.tar.gz root@ubuntu:/usr/local/src# ln -sv /usr/local/src/jdk1.8.0_191 /usr/local/jdk #:配置环境变量 root@ubuntu:/usr/local/src# vim /etc/profile export JAVA_HOME=/usr/local/jdk export TOMCAT_HOME=/apps/tomcat export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$TOMCAT_HOME/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar root@ubuntu:/usr/local/src# source /etc/profile #:下载war包 root@ubuntu:/usr/local/src# mkdir /data/jenkins -pv root@ubuntu:/usr/local/src# cd /data/jenkins/ #:启动服务 root@ubuntu:/data/jenkins# java -jar jenkins.war
#:
#基于Tomcat装jenkins的war包 #:先将业务停掉 root@ubuntu:/data/tomcat/tomcat_webapps# /etc/init.d/tomcat stop #:准备war包 root@ubuntu:/data/tomcat/tomcat_webapps# ls jenkins.war #:解压 root@ubuntu:/data/tomcat/tomcat_webapps# unzip jenkins.war -d jenkins root@ubuntu:/data/tomcat/tomcat_webapps# chown -R tomcat.tomcat /data/tomcat/ #:切换到Tomcat启动服务 root@ubuntu:/data/tomcat/tomcat_webapps# su - tomcat tomcat@ubuntu:~$ /etc/init.d/tomcat start #:直接测试访问会出错,安装一下包 root@ubuntu:/data/tomcat/tomcat_webapps# apt-get install libxrender-dev root@ubuntu:/data/tomcat/tomcat_webapps# apt-get install libxtst-dev