java項(xiàng)目代碼上線

1:java項(xiàng)目代碼上線架構(gòu)圖

image
ip地址及主機(jī)名規(guī)劃
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服務(wù)器并上傳代碼

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
上傳項(xiàng)目代碼到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服務(wù)器和數(shù)據(jù)庫(kù)

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啟動(dòng)加速的方法
vim /usr/java/jdk1.8.0_102/jre/lib/security/java.security
修改117行為:securerandom.source=file:/dev/urandom
/application/tomcat/bin/startup.sh
為項(xiàng)目準(zhǔn)備好數(shù)據(jù)庫(kù)jeesns,設(shè)置數(shù)據(jù)庫(kù)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中添加密鑰對(duì)
git clone git@git.oldboyedu.com:root/jeesns.git
b:編譯項(xiàng)目代碼
cd jeesns/
mvn clean package
c:數(shù)據(jù)庫(kù)升級(jí)
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:遠(yuǎn)程推送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

測(cè)試訪問:

image.png
把上面的第五步(編譯和部署)用shell腳本來實(shí)現(xiàn),這個(gè)腳本就是shell自動(dòng)化上線腳本
把上面的第五步用jenkins來實(shí)現(xiàn),即jenkins+gitlab代碼自動(dòng)上線。
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容