友情提示
代码上线流程中默认大家有root权限!!!!
方便大家模拟项目上线流程,实际生产环境中大家要特别注意!
训练也是为了实战!时刻想着实战,养成良好习惯!切记!规范!
不听老人言吃亏在眼前!罚款、翻车、遭白眼!
1:java项目代码上线架构图
14410242-4561d39148f668ec.pngip地址及主机名规划
10.0.0.11 deploy
10.0.0.12 tomcat-web01
10.0.0.13 git.azkaban.com
2:部署gitlab服务器并上传代码
wget https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.4.5-ce.0.el7.x86_64.rpm
yum localinstall gitlab-ce-11.4.5-ce.0.el7.x86_64.rpm -y
vim /etc/gitlab/gitlab.rb
external_url 'http://git.azkaban.com'
gitlab-ctl reconfigure
上传项目代码到gitlab
rz jeesns.tar.gz
tar xf jeesns.tar.gz
cd jeesns/
rm -fr .git*
git init
git remote add origin http://git.azkaban.com/root/jeesns.git
git add *
git commit -m '初始提交'
git push -u origin master
#### 3:部署tomcat服务器和数据库
rz jdk-8u102-linux-x64.rpm
rz apache-tomcat-8.0.27.tar.gz
rpm -ivh jdk-8u102-linux-x64.rpm
mkdir /application/
tar zvxf apache-tomcat-8.0.27.tar.gz -C /application/
mv /application/apache-tomcat-8.0.27 /application/tomcat
#tomcat启动加速的方法
vim /usr/java/jdk1.8.0_102/jre/lib/security/java.security
修改117行为:securerandom.source=file:/dev/urandom
/application/tomcat/bin/startup.sh
为项目准备好数据库jeesns,设置数据库root用户密码为root
yum install mariadb-server -y
mysql_secure_installation
mysqladmin -uroot password 'root'
mysql -uroot -proot -e 'create database jeesns;'
#### 4:安装maven
rz jdk-8u102-linux-x64.rpm
rpm -ivh jdk-8u102-linux-x64.rpm
wget https://mirror.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz
tar xf apache-maven-3.6.0-bin.tar.gz
mv apache-maven-3.6.0 /usr/local/
ln -s /usr/local/apache-maven-3.6.0 /usr/local/maven
vim /etc/profile
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:$PATH
source /etc/profile
mvn -v
#### 5:编译和部署(上线)
a:代码拉取
#需要在gitlab中添加密钥对
git clone git@git.azkaban.com:root/jeesns.git
b:编译项目代码
cd jeesns/
mvn clean package
c:数据库升级
yum install sshpass -y
sshpass -p123456 scp /opt/jeesns/jeesns-web/database/jeesns.sql root@10.0.0.12:/tmp
sshpass -p123456 ssh root@10.0.0.12 'mysql -uroot -proot jeesns </tmp/jeesns.sql'
d:远程推送war包
sshpass -p123456 ssh root@10.0.0.12 'mv /application/tomcat/webapps/* /opt'
sshpass -p123456 scp -rp /opt/jeesns/jeesns-web/target/jeesns-web.war 10.0.0.12:/application/tomcat/webapps/ROOT.war
测试访问:
14410242-2cb0b40746215b46.png把上面的第五步(编译和部署)用Shell脚本来实现,这个脚本就是Shell自动化上线脚本
把上面的第五步用jenkins来实现,即jenkins+gitlab代码自动上线。
网友评论