Linux offline installation of Jenkins, Maven, Gitlab, Git, deployment of Java projects

install java

"Linux install java"

Install Maven

insert image description here
Upload Maven to the Linux server /data/ directory for decompression

cd /data/ && tar -zxvf apache-maven-3.9.3-bin.tar.gz

Configure environment variables

vim /etc/profile

Find export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL append below

# maven
export MAVEN_HOME=/data/apache-maven-3.9.3
export PATH=$MAVEN_HOME/bin:$PATH

After saving, make the environment variable take effect and check whether maven is installed successfully

source /etc/profile && mvn -version

Modify the default dependency warehouse location

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,Append the comment

<localRepository>/data/apache-maven-3.9.3/repository/</localRepository>

Configure mirroring, find the mirrors tag, and add the following content to it

        <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>

Install GitLab

"GitLab official website download"
My system is Centos7, so I downloaded the el/7 version. 7 is the version number of the operating system.
insert image description here
Choose the corresponding installation method. I am in an offline environment, so I choose offline installation (download speed is slow, you can use a third-party download Tools, such as: Thunder, etc.)
insert image description here

Install offline

The python library that gitlab depends on, policycoreutils-python is needed by gitlab-ce-16.0.7-ce.0.el7.x86_64
, find a virtual machine that can be connected to the Internet to download the corresponding policycoreutils-python rpm package

yum install policycoreutils-python --downloadonly --downloaddir=/data/gitlab_rpm/

Copy these rpm packages to the intranet /data/gitlab_rpm/ folder for offline installation.
insert image description here
It is best to store the rpm packages in the same folder on the offline machine for installation

cd /data/gitlab_rpm/ && rpm -ivh *.rpm --force --nodeps

Install gitlab offline

cd /data/ && rpm -ivh gitlab-ce-16.0.7-ce.0.el7.x86_64.rpm

If you see the following icon, it means the installation is successful.
insert image description here
Modify the ip and port number

vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.1.111:8800'

Reload the gitlab configuration file (the process may be a bit long)

gitlab-ctl reconfigure

View gitlab initial password

cat /etc/gitlab/initial_root_password

Open the firewall and enter the gitlab console to change the initial password

systemctl stop firewalld && systemctl disable firewalld

insert image description here

Modify Gitlab initial password

insert image description here
insert image description here

Modify the Gitlab language to Chinese

insert image description here

insert image description here
Then slide to the bottom to save the Save changes

Modify Gitlab storage location

Create a gitlab data storage directory and stop gitlab

mkdir -p /data/gitlab/data/ && gitlab-ctl stop

Move the gitlab installation directory to the /data directory

cp -R /var/opt/gitlab /data

Modify the data storage directory

vim  /etc/gitlab/gitlab.rb

Don't press I to enter, look up variables

/git_data_dirs(

Modify the path to /data/gitlab/git-data

# 因为默认的git_data_dirs是被注释掉了,我们直接在他下面追加如下内容即可。
git_data_dirs({
    
    
   "default" => {
    
    
     "path" => "/data/gitlab/git-data"
   }
})

Give the file we created 777 permissions

chmod  -R 777 /data/gitlab/git-data/repositories

Make the configuration file take effect and restart gitlab

gitlab-ctl reconfigure && gitlab-ctl restart

Install Git

"Git compressed package tar.gz download"
insert image description here
git related dependencies [still the old way, first download to the virtual machine, then pack it and install it in an offline environment]

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc-c++ perl-ExtUtils-MakeMaker --downloadonly --downloaddir=/data/git_rpm/

Install the dependencies required by git

cd /data/git_rpm/ && rpm -ivh *.rpm --force --nodeps

Upload to the usr/loacl/ directory of the linux server and decompress it

tar -zxvf /usr/local/v2.39.0.tar.gz -C /usr/local/

Install git offline

cd /usr/local/git-2.39.0/
make prefix=/usr/local/git-2.39 all
make prefix=/usr/local/git-2.39 install

Configure environment variables

vim /etc/profile

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROLAdditional content

# git
export GIT_HOME=/usr/local/git-2.39
export PATH=$GIT_HOME/bin:$PATH

Save, make the configuration file take effect and check whether git is installed successfully

source /etc/profile && git -v

Install Jenkins

"Jenkins Chinese Official Website"
insert image description here
insert image description here
insert image description here
Find the Jenkins version we need through web search
insert image description here

Download the corresponding war package (download is slow, you can copy the download link and use a third-party download tool to speed up the download, such as: Thunder, etc.)
insert image description here
jdk17 may lack font dependencies [still the old method]

yum install fontconfig --downloadonly --downloaddir=/data/java/
cd /data/java/ && rpm -ivh *.rpm --force --nodeps
fc-cache --force

deploy

Create a jenkins storage folder, enter the folder, and upload the war package to this directory

mkdir -p /data/jenkins/ && cd /data/jenkins/

Start jenkins after uploading the war package, make sure java is installed and environment variables are configured

nohup java -jar jenkins.war --httpPort=8811 >nohup.out 2>&1 &

Check whether jenkins starts successfully (it may take 30-60 seconds)

cat nohup.out

if output
View the initial password
root is the folder of the current login user, if your login user is other, replace it with the corresponding login user for viewing.

cat /root/.jenkins/secrets/initialAdminPassword

Initial account: admin (if any)
Initial password: f4c5d63605124461aeffb8180b639908 (that is, the password viewed through the command above)

Install the plugin (use its recommended install)

Required:Maven Integration plugin、Publish Over SSH
First install the plug-in in the virtual machine, then copy the jpi file under /root/.jenkins/plugins/ and paste it to the offline environment /root/.jenkins/plugins/
root is the user's folder address, if you are not using the root user, change it to the login user you installed jenkins
insert image description here

Configure global variables

This is the Maven used by Jenkins

insert image description here

Compile the project's JDKinsert image description here
Pull the project to Git

insert image description here

Deploy project Maven

insert image description here

System Configuration

java environment variable

insert image description here

Git environment variables

Continue to add
insert image description here

Pull to the bottom of the Publish over SSH configuration deployment server, which is the server running the project

insert image description here

Build a maven project

insert image description here

Go to Gitlab to copy the code address

insert image description here

Go back to jenkins and paste the copied address

insert image description here
solveremote: 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.Error
insert image description here
insert image description here
insert image description here
Check the main branch name of Gitlab, some are master and some are main
insert image description here

Save for last.
insert image description here
If you report an error, just look at the error message output by the console to Baidu
insert image description here

The deployment server manually starts the jar package (Remember to open the corresponding port on the firewall to avoid inaccessibility

[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 test code
startup class

@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 configuration server.port: 9090
pom.xml

		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

Browser access 192.168.56.12:9090/hello
insert image description here

Next

"Jenkins automatically publishes to the server and runs automatically"

Guess you like

Origin blog.csdn.net/weixin_43933728/article/details/131678582