java項目代碼上線


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代碼自動上線。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM