Deploy Java project (1)-create a private warehouse, download zrlog source code, install and configure Tomcat, install maven

Jenkins deploy java project

We used jenkins to publish PHP code before, but this kind of demand may not be used much in the production environment. Instead, it is more used to deploy java projects. Java projects need to be compiled and packaged. Compilation and packaging are done with maven, so maven needs to be installed.

Create a private warehouse

First, build a private warehouse. For specific steps, please refer to the previous notes. Here I use another machine, jinkai05, to build a gitlab server. The IP is 192.168.111.140.

surroundings:

jinkai01 ip: 192.168.111.136 role: jenkins server

jinkai02 ip: 192.168.111.137 role: deployment machine

jinkai05 ip: 192.168.111.140 role: gitlab server

Install gitlab on jinikai05:

# vim /etc/yum.repos.d/gitlab.repo

[gitlab-this]

name=Gitlab CE Repository

baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/

gpgcheck=0

enabled=1

Install dependent packages:

yum -y install curl openssh-server openssh-clients postfix cronie

Install gitlab

yum install -y gitlab-ce

Configure gitlab

gitlab-ctl reconfigure

Start service

gitlab-ctl restart

View port

netstat -lntp

Check status

gitlab-ctl status

After starting the service, enter the IP directly on the webpage: 192.168.111.140 to visit

You will be prompted to reset the password---the default user root and the new password to log in

Create a new project—customize the project name

img img

After clicking save, the following page will pop up. It is recommended to copy the link and reopen a window. We need to set the SSH Key first

img

Generate the public key on the Jinkai01 machine and paste it into SSH Keys:

Generate key pair: ssh-keygen

View the public key:

[root@jinkai wuhaha]# cat /root/.ssh/id_rsa.pub

img img

Open the new window where you just copied the link, and execute it on the jinkai01 server according to the configuration here:

img

Global Settings

[root @ jinkai wuhaha] # cd / home /

[root@jinkai home]# git config --global user.name "Administrator"

[root@jinkai home]# git config --global user.email [email protected]

Create a new warehouse

[root@jinkai home]# git clone [email protected]:root/jinkai05.git

Being cloned to'jinkai05'...

warning: You seem to have cloned an empty repository.

[root @ jinkai home] # cd jinkai05 /

[root @ jinkai jinkai05] # touch README.md

[root@jinkai jinkai05]# git add README.md

[root@jinkai jinkai05]# git commit -m "add README"

[master (root submission) cac5983] add README

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README.md

[root@jinkai jinkai05]# git push -u origin master

Counting objects: 3, done.

Writing objects: 100% (3/3), 216 bytes | 0 bytes/s, done.

Total 3 (delta 0), reused 0 (delta 0)

To [email protected]:root/jinkai05.git

* [new branch] master -> master

The branch master is set to track the remote branch master from origin.

Refresh the browser interface, you can see the README.md file just uploaded

img

At this point, our private warehouse is created.

Download Zrlog source code

ZrLog is a blog/CMS program developed in Java. It has the characteristics of simplicity, ease of use, componentization, and low memory usage. It comes with a Markdown editor. Here we use the source code of Zrlog as the java code for testing.

Download the source code of zrlog on Jinkai01** :**

[root@jinkai home]# wget

https://codeload.github.com/94fzb/zrlog/zip/master

[root@jinkai home]# yum install -y unzip

[root@jinkai home]# unzip master

[root @ jinkai home] # ls

albert jinkai05 linuxprobe master wuhaha zrlog-master

[root @ jinkai home] # ls zrlog-master /

admin-frontend common doc LICENSE mvnw.cmd README.en-us.md service

bin data install-frontend mvnw pom.xml README.md web

Move to the jinkai05 directory:

[root@jinkai home]# mv zrlog-master/* jinkai05/

mv: Whether to overwrite "jinkai05/README.md"? yes

[root @ jinkai home] # cd jinkai05 /

[root @ jinkai jinkai05] # ls

admin-frontend common doc LICENSE mvnw.cmd README.en-us.md service

bin data install-frontend mvnw pom.xml README.md web

Upload to gitlab server:

[root@jinkai jinkai05]# git add .

[root@jinkai jinkai05]# git commit -m "add zrlog"

[root@jinkai jinkai05]# git push

Counting objects: 596, done.

Compressing objects: 100% (544/544), done.

Writing objects: 100% (594/594), 1.75 MiB | 0 bytes/s, done.

Total 594 (delta 82), reused 0 (delta 0)

remote: Resolving deltas: 100% (82/82), done.

To [email protected]:root/jinkai05.git

cac5983..2a953b1 master -> master

Refresh the browser interface, you can see the zrlog file just uploaded

img

Install tomcat

Here is another machine jinkai02 to install jdk and tomcat, the jdk here cannot use openjdk, otherwise an error will be reported later. For specific installation steps, please refer to here:

Install JDK

Official website download address:

https://www.oracle.com/java/technologies/javase-downloads.html

My computer has stored the jdk installation package, so I uploaded it directly

[root@localhost ~]# cd /usr/local/src/

[root@localhost src]# rz

Unzip, move

[root@localhost src]# tar -xzvf jdk-14.0.2_linux-x64_bin.tar.gz

[root@localhost src]# mv jdk-14.0.2 /usr/local/jdk-14

Set environment variables

vim /etc/profile

Add the following

JAVA_HOME=/usr/local/jdk-14/

JAVA_BIN=/usr/local/jdk-14/bin

JRE_HOME=/usr/local/jdk-14/jre

PATH=$PATH:/usr/local/jdk-14/bin:/usr/local/jdk-14/jre/bin

CLASSPATH=/usr/local/jdk-14/jre/lib:/usr/local/jdk-14/lib:/usr/local/jdk-14/jre/lib/charsets.jar

Effective immediately:

source /etc/profile

Check whether the settings are correct

java -version

java version "14.0.2" 2020-07-14

Java(TM) SE Runtime Environment (build 14.0.2+12-46)

Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)

Install tomcat:

Official website download address: http://tomcat.apache.org/

Download the installation package:

[root@localhost src]# wget https://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.tar.gz

Unzip the installation package and move

[root@localhost src]# tar -xzvf apache-tomcat-9.0.41.tar.gz

[root@localhost src]# mv apache-tomcat-9.0.41 /usr/local/tomcat

Start Tomcat

[root@localhost src]# /usr/local/tomcat/bin/startup.sh

Using CATALINA_BASE: /usr/local/tomcat

Using CATALINA_HOME: /usr/local/tomcat

Using CATALINA_TMPDIR: /usr/local/tomcat/temp

Using JRE_HOME: /usr/local/jdk-14

Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Using CATALINA_OPTS:

Tomcat started.

Check whether the startup is successful

[root@localhost src]# ps aux | grep tomcat

[root@localhost src]# netstat -lntp

Set boot up

[root@localhost src]# echo

"/usr/local/tomcat/bin/startup.sh" >> /etc/rc.d/rc.local

[root@localhost src]# chmod a+x /etc/rc.d/rc.local

Turn off the firewall and use the browser to access:

[root@localhost src]#systemctl stop firewalld

[root@localhost src]# systemctl disable firewalld

Open the browser, enter the machine ip: port 8080 to access

img

We click on the manager webapp in the above figure, and we will find that it is a 403 alarm, as shown in the figure below

img

Edit configuration file

vim /usr/local/tomcat/webapps/manager/META-INF/context.xml

Edit the following content and add a 92.168.111.* paragraph

allow="127.\d+.\d+.\d+|::1|0:0:0:0:0:0:0:1|192.168.111.*" />

Restart tomcat

[root@localhost src]# /usr/local/tomcat/bin/shutdown.sh

Using CATALINA_BASE: /usr/local/tomcat

Using CATALINA_HOME: /usr/local/tomcat

Using CATALINA_TMPDIR: /usr/local/tomcat/temp

Using JRE_HOME: /usr/local/jdk-14

Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Using CATALINA_OPTS:

NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED

[root@localhost src]# /usr/local/tomcat/bin/startup.sh

Using CATALINA_BASE: /usr/local/tomcat

Using CATALINA_HOME: /usr/local/tomcat

Using CATALINA_TMPDIR: /usr/local/tomcat/temp

Using JRE_HOME: /usr/local/jdk-14

Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Using CATALINA_OPTS:

Tomcat started.

Refresh the tomcat interface, a pop-up window appears, prompting to enter the user name and password

img

Add tomcat users

vim /usr/local/tomcat/conf/tomcat-users.xml

Add the following content above the bottom line </tomcat-users>

<role rolename="admin"/>

<role rolename="admin-gui"/>

<role rolename="admin-script"/>

<role rolename="manager"/>

<role rolename="manager-gui"/>

<role rolename="manager-script"/>

<role rolename="manager-jmx"/>

<role rolename="manager-status"/><user name="tomcat" password="admin123" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status"/>

#Add user tomcat, password is admin123, which will be used later

Restart tomcat

[root@localhost src]# /usr/local/tomcat/bin/shutdown.sh

[root@localhost src]# /usr/local/tomcat/bin/startup.sh

Refresh the browser interface, enter the username and password you just added, and enter the tomcat management page

img

Only when jenkins accesses this back-end management interface can the war package be released.

Install maven

Maven is used to compile the source code and package, download address: http://maven.apache.org/download.cgi .

To install maven on the jenkins machine, it must be operated on the jinkai01 machine.

Download and install:

[root@jinkai src]# wget

https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Unzip:

[root @ jinkai src] # tar -xzvf apache-maven-3.6.3-bin.tar.gz

View version:

[root@jinkai src]# apache-maven-3.6.3/bin/mvn --version

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Maven home: /usr/local/src/apache-maven-3.6.3

Java version: 1.8.0_272, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.272.b10-1.el7_9.x86_64/jre

Default locale: zh_CN, platform encoding: UTF-8

OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"

Configure jenkins:

Manage jenkins → Global Tool Configuration, find the Maven configuration

The default settings provide-select the settings file in the file system, and fill in the path of the settings file in the file path;

The default global settings provide-select the global settings file in the file system, the file path fills in the path of the settings file.

img

img

Find Maven, click Add Maven, customize the name, uncheck the automatic installation, fill in the path of the newly installed maven, and save the application

img

Guess you like

Origin blog.51cto.com/11451960/2640811