安裝Java
《Linux安裝java》
安裝Maven
把Maven上傳到Linux服務(wù)器/data/目錄下進行解壓
cd /data/ && tar -zxvf apache-maven-3.9.3-bin.tar.gz
配置環(huán)境變量
vim /etc/profile
找到export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL在下面追加
# maven
export MAVEN_HOME=/data/apache-maven-3.9.3
export PATH=$MAVEN_HOME/bin:$PATH
保存后使環(huán)境變量生效并校驗是否maven是否安裝成功
source /etc/profile && mvn -version
修改默認依賴倉庫位置
mkdir -p /data/apache-maven-3.9.3/repository && vim /data/apache-maven-3.9.3/conf/settings.xml
找到localRepository>/path/to/local/repo</localRepository,在注釋外面追加
<localRepository>/data/apache-maven-3.9.3/repository/</localRepository>
配置鏡像,找到mirrors標簽,在里面追加如下內(nèi)容
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共倉庫</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<!-- spring-->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共倉庫</name>
<url>https://maven.aliyun.com/repository/spring</url>
</mirror>
<!-- spring-plugin-->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共倉庫</name>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
</mirror>
<!-- google-->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共倉庫</name>
<url>https://maven.aliyun.com/repository/google</url>
</mirror>
<!-- grails-core-->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共倉庫</name>
<url>https://maven.aliyun.com/repository/grails-core</url>
</mirror>
<!-- apache snapshots-->
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共倉庫</name>
<url>https://maven.aliyun.com/repository/apache-snapshots</url>
</mirror>
安裝GitLab
《GitLab官網(wǎng)下載》
我的系統(tǒng)是Centos7 因此下載el/7版本的,7就是操作系統(tǒng)的版本號
選擇對應(yīng)的安裝方式,我是離線環(huán)境,因此選擇離線安裝(下載速度慢,可以使用第三方下載工具,如:迅雷等)
離線安裝
gitlab依賴的python庫,policycoreutils-python is needed by gitlab-ce-16.0.7-ce.0.el7.x86_64
,找臺能聯(lián)網(wǎng)的虛擬機下載對應(yīng)的policycoreutils-python rpm 包
yum install policycoreutils-python --downloadonly --downloaddir=/data/gitlab_rpm/
把這些rpm包復(fù)制到內(nèi)網(wǎng)/data/gitlab_rpm/文件夾下進行離線安裝
最好離線機器也放到同一個文件夾下存放rpm包,進行安裝
cd /data/gitlab_rpm/ && rpm -ivh *.rpm --force --nodeps
離線安裝gitlab
cd /data/ && rpm -ivh gitlab-ce-16.0.7-ce.0.el7.x86_64.rpm
看到如下圖標就表示安裝成功了
修改ip和端口號
vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.1.111:8800'
重新加載gitlab配置文件(過程可能有點長)
gitlab-ctl reconfigure
查看gitlab初始密碼
cat /etc/gitlab/initial_root_password
開放防火墻進入gitlab控制臺修改初始密碼
systemctl stop firewalld && systemctl disable firewalld
修改Gitlab初始密碼
修改Gitlab語言為中文
然后滑到最下面進行Save changes保存
修改Gitlab存儲位置
創(chuàng)建gitlab數(shù)據(jù)存儲目錄并停止gitlab
mkdir -p /data/gitlab/data/ && gitlab-ctl stop
移動gitlab安裝目錄到/data目錄下
cp -R /var/opt/gitlab /data
修改數(shù)據(jù)存放目錄
vim /etc/gitlab/gitlab.rb
不要按I輸入,查找變量
/git_data_dirs(
修改path為/data/gitlab/git-data
# 因為默認的git_data_dirs是被注釋掉了,我們直接在他下面追加如下內(nèi)容即可。
git_data_dirs({
"default" => {
"path" => "/data/gitlab/git-data"
}
})
給我們創(chuàng)建的文件777權(quán)限
chmod -R 777 /data/gitlab/git-data/repositories
使配置文件生效并重啟gitlab
gitlab-ctl reconfigure && gitlab-ctl restart
安裝Git
《Git壓縮包tar.gz下載》
git相關(guān)依賴【還是老辦法,先下載到虛擬機,再打包放到離線環(huán)境安裝】
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc-c++ perl-ExtUtils-MakeMaker --downloadonly --downloaddir=/data/git_rpm/
安裝git需要的依賴
cd /data/git_rpm/ && rpm -ivh *.rpm --force --nodeps
上傳到linux服務(wù)器的usr/loacl/目錄下解壓
tar -zxvf /usr/local/v2.39.0.tar.gz -C /usr/local/
離線安裝git
cd /usr/local/git-2.39.0/
make prefix=/usr/local/git-2.39 all
make prefix=/usr/local/git-2.39 install
配置環(huán)境變量
vim /etc/profile
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL追加內(nèi)容
# git
export GIT_HOME=/usr/local/git-2.39
export PATH=$GIT_HOME/bin:$PATH
保存,使配置文件生效并查看git是否安裝成功
source /etc/profile && git -v
安裝Jenkins
《Jenkins中文官網(wǎng)》
通過網(wǎng)頁搜索找到我們需要的Jenkins版本
下載對應(yīng)的war包(下載慢可以復(fù)制下載鏈接用第三方下載工具加速下載,如:迅雷等。)
jdk17可能會缺少字體依賴【還是老辦法】
yum install fontconfig --downloadonly --downloaddir=/data/java/
cd /data/java/ && rpm -ivh *.rpm --force --nodeps
fc-cache --force
部署
創(chuàng)建jenkins存放文件夾,并進入該文件夾,上傳war包到這個目錄下
mkdir -p /data/jenkins/ && cd /data/jenkins/
上傳完war包以后啟動jenkins,確保已經(jīng)安裝好java和配置好環(huán)境變量
nohup java -jar jenkins.war --httpPort=8811 >nohup.out 2>&1 &
查看jenkins是否啟動成功(可能要等個30-60秒)
cat nohup.out
查看初始密碼
root是當(dāng)前登錄用戶的文件夾,如果你的登錄用戶是其它則替換成對應(yīng)的登錄用戶進行查看.
cat /root/.jenkins/secrets/initialAdminPassword
初始賬號:admin(如果有的話)
初始密碼:f4c5d63605124461aeffb8180b639908(就是上面通過命令查看的密碼)
安裝插件(建議使用它的推薦安裝)
必裝:Maven Integration plugin、Publish Over SSH
先在虛擬機安裝好插件,到時候復(fù)制/root/.jenkins/plugins/下的jpi文件粘貼到離線環(huán)境/root/.jenkins/plugins/
root是用戶的文件夾地址,如果你不是用root用戶,則改成你安裝jenkins的登錄用戶
配置全局變量
這個是Jenkins使用的Maven
編譯項目的JDK
拉去項目的Git
部署項目的Maven
系統(tǒng)配置
java環(huán)境變量
Git環(huán)境變量
繼續(xù)新增
拉到最底下的 Publish over SSH配置部署服務(wù)器,就是運行項目的服務(wù)器
構(gòu)建一個maven項目
去Gitlab拷貝代碼地址
回到j(luò)enkins粘貼復(fù)制的地址
解決 remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. 錯誤
查看Gitlab的主分支名稱,有的是master有的是main
最后保存。
報錯就看控制臺輸出的錯誤信息去百度
部署服務(wù)器手動啟動jar包(防火墻記得開放相應(yīng)端口,避免無法訪問)
[root@node2 /]# cd /docker_data/jenkins/home/workspace/first/target/
[root@node2 target]# java -jar gitlabdemo-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.6)
2022-12-14 08:12:22.723 INFO 41645 --- [ main] com.fu.gitlabdemo.GitlabdemoApplication : Starting GitlabdemoApplication v0.0.1-SNAPSHOT using Java 1.8.0_341 on node2 with PID 41645 (/docker_data/jenkins/home/workspace/first/target/gitlabdemo-0.0.1-SNAPSHOT.jar started by root in /docker_data/jenkins/home/workspace/first/target)
2022-12-14 08:12:22.726 INFO 41645 --- [ main] com.fu.gitlabdemo.GitlabdemoApplication : No active profile set, falling back to 1 default profile: "default"
2022-12-14 08:12:23.926 INFO 41645 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http)
2022-12-14 08:12:23.951 INFO 41645 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-14 08:12:23.951 INFO 41645 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.69]
2022-12-14 08:12:24.239 INFO 41645 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-14 08:12:24.239 INFO 41645 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1448 ms
2022-12-14 08:12:24.772 INFO 41645 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9090 (http) with context path ''
2022-12-14 08:12:24.786 INFO 41645 --- [ main] com.fu.gitlabdemo.GitlabdemoApplication : Started GitlabdemoApplication in 2.517 seconds (JVM running for 2.991)
springboot測試代碼
啟動類
@RestController
@SpringBootApplication
public class GitlabdemoApplication {
public static void main(String[] args) {
SpringApplication.run(GitlabdemoApplication.class, args);
}
@GetMapping("hello")
public String hello(){
return "hello world!";
}
}
yml配置server.port: 9090
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
瀏覽器訪問192.168.56.12:9090/hello文章來源:http://www.zghlxwxcb.cn/news/detail-729428.html
下一篇
《jenkins自動化發(fā)布到服務(wù)器并自動運行》文章來源地址http://www.zghlxwxcb.cn/news/detail-729428.html
到了這里,關(guān)于Linux離線安裝Jenkins、Maven、Gitlab、Git,部署Java項目的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!