开放防火墙端口80和配置映射文件夹
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
mkdir -p /docker_data/gitlab/{data,logs,config}
启动Gitlab容器(启动容器之前确保80,443端口没用被占用,被占用就改成其它的。这个启动比较费时,我差点认为它没跑起来!)
docker run -d --hostname 192.168.1.11 -p 80:80 -p 443:443 --privileged=true --restart=always -v /docker_data/gitlab/config:/etc/gitlab -v /docker_data/gitlab/data:/var/opt/gitlab -v /docker_data/gitlab/logs:/var/log/gitlab --shm-size 256m --name gitlab-ce-15.6.2 gitlab/gitlab-ce:15.6.2-ce.0
获取Gitlab密码(gitlab-ce-15.6.2是容器名称,我个人习惯用容器名称 - 版本号命名)
docker exec -it gitlab-ce-15.6.2 grep 'Password:' /etc/gitlab/initial_root_password
ip:80访问,账号:root,密码就是上面那行命令输出的。
太长了分开写《docker安装Gitlab》
《Linux之Centos7安装JDK17》想装jdk8就下载jdk,操作也是一样的。
wget -P /docker_data/jenkins/maven/ https://archive.apache.org/dist/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
解压到指定文件夹
tar -zxvf /docker_data/jenkins/maven/apache-maven-3.8.1-bin.tar.gz -C /docker_data/jenkins/maven/
设置环境变量
vim /etc/profile
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL追加内容
# maven
export MAVEN_HOME=/docker_data/jenkins/maven/apache-maven-3.8.1
export PATH=$PATH:$MAVEN_HOME/bin
保存,使配置文件生效并查看mavn是否配置成功
source /etc/profile
mvn -version
配置镜像
vim /docker_data/jenkins/maven/apache-maven-3.8.1/conf/settings.xml
替换掉整个mirrors
<mirrors>
<mirror>
<id>mirrorIdid>
<mirrorOf>repositoryIdmirrorOf>
<name>Human Readable Name for this Mirror.name>
<url>http://my.repository.com/repo/pathurl>
mirror>
-->
<mirror>
<id>aliyunmavenid>
<mirrorOf>*mirrorOf>
<name>阿里云公共仓库name>
<url>https://maven.aliyun.com/repository/publicurl>
mirror>
<mirror>
<id>aliyunmavenid>
<mirrorOf>*mirrorOf>
<name>阿里云公共仓库name>
<url>https://maven.aliyun.com/repository/springurl>
mirror>
<mirror>
<id>aliyunmavenid>
<mirrorOf>*mirrorOf>
<name>阿里云公共仓库name>
<url>https://maven.aliyun.com/repository/spring-pluginurl>
mirror>
<mirror>
<id>aliyunmavenid>
<mirrorOf>*mirrorOf>
<name>阿里云公共仓库name>
<url>https://maven.aliyun.com/repository/googleurl>
mirror>
<mirror>
<id>aliyunmavenid>
<mirrorOf>*mirrorOf>
<name>阿里云公共仓库name>
<url>https://maven.aliyun.com/repository/grails-coreurl>
mirror>
<mirror>
<id>aliyunmavenid>
<mirrorOf>*mirrorOf>
<name>阿里云公共仓库name>
<url>https://maven.aliyun.com/repository/apache-snapshotsurl>
mirror>
mirrors>
yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum -y install gcc-c++ perl-ExtUtils-MakeMaker
上传到linux服务器的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
配置环境变量
vim /etc/profile
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL追加内容
# git
export GIT_HOME=/usr/local/git-2.39
export PATH=$GIT_HOME/bin:$PATH
保存,使配置文件生效并查看git是否安装成功
source /etc/profile
git -v
开放防护墙端口和创建宿主机文件夹
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
mkdir -p /docker_data/jenkins/home
-u 0表示使用超级管理员启动
docker run -u 0 -d -p 8080:8080 -p 50000:50000 --privileged=true --restart=always -v /usr/local/java/jdk1.8.0_341:/usr/local/jdk -v /docker_data/jenkins/maven/apache-maven-3.8.1:/usr/local/maven -v /usr/local/git-2.39/bin/git:/usr/local/git -v /docker_data/jenkins/home:/var/jenkins_home -v /etc/localtime:/etc/localtime -e JAVA_OPTS="-server -Xms2048m -Xmx2048m" --name jenkins-jdk17 jenkins/jenkins:jdk17
查看jenkins初始密码
[root@node1 ~]# docker exec -it jenkins-jdk17 bash
root@10203976ba44:/# cat /var/jenkins_home/secrets/initialAdminPassword
e7944399aba54dcdb43488fc2feb5ad2
ip:8080访问jenkins可视化界面,输入密码登录,选择安装推荐的插件。
账号:root
密码:123456
Jenkins URL:http://192.168.1.11:8080/(默认即可,一般jenkins会专门用一台服务器)
安装Localization: Chinese (Simplified)、Maven Integration plugin、Publish Over SSH三个插件
拉到最底下的 Publish over SSH配置部署服务器,就是运行项目的服务器
部署服务器创建部署文件夹
mkdir /jenkins
去Gitlab拷贝代码地址
回到jenkins粘贴复制的地址
解决 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
[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.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>