java项目代码上线
1:java项目代码上线架构图
ip地址及主机名规划
10.0.0.11 deploy
10.0.0.12 tomcat-web01
10.0.0.13 git.oldboyedu.com
资料包下载地址:链接:https://pan.baidu.com/s/1YIgnUOkWLtp-LoQpIt-qVg 提取码:mpjb
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.oldboyedu.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.oldboyedu.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.oldboyedu.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
测试访问:
把上面的第五步(编译和部署)用shell脚本来实现,这个脚本就是shell自动化上线脚本
把上面的第五步用jenkins来实现,即jenkins+gitlab代码自动上线。
评论已关闭