In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This paper takes the deployment of Spring boot + Maven project as an example, uses Code Cloud as a code hosting repository, and builds a Jenkins continuous integration environment on CentOS 7.
1. Preparatory work
1.1 install the Java environment
Jenkins is a continuous integration tool based on Java development, which needs to run in Java environment. Check to see if Java is installed on the system with the following command:
Yum list installed | grep jdk
If not, use the yum search command to find the openjdk version and select the appropriate jdk to install:
Yum search openjdk yum-y install java-1.8.0-openjdk-devel
Verify that Java is installed successfully:
Java-version
1.2 install Maven
Run the following two commands in turn:
Wget http://repos.fedorapeople.org... -O / etc/yum.repos.d/epel-apache-maven.repo yum-y install apache-maven
Verify that Maven is installed successfully:
Mvn-v
1.3 install Git
Install directly through yum. After the installation is complete, check the version to verify whether the installation is successful:
Yum-y install git git-- version
two。 Install and configure Jenkins:
2.1 install Jenkins
Run the following three commands in turn:
Sudo wget https://pkg.jenkins.io/redhat... -O / etc/yum.repos.d/jenkins.repo sudo rpm-- import https://pkg.jenkins.io/redhat... Yum-y install jenkins
If you have previously imported key from Jenkins, rpm-- import will fail because there is already a key. Ignore it and continue with install.
2.2 start Jenkins
Start Jenkins and set up boot self-boot:
Systemctl start jenkins.service chkconfig jenkins on
Jenkins uses port 8080 by default. Visit the following link to see the Web interface of Jenkins:
Http://:8080
If you can't access it, check the walls for open ports, or use the command netstat-ntulp to see if the ports are occupied.
2.3 enter Jenkins
To enter Jenkins for the first time, you need to enter the administrator password. Use the following command to view the initial password:
Cat / var/lib/jenkins/secrets/initialAdminPassword
Select the default install suggested plugins installation plug-in, wait for the installation to complete, follow the steps to create the user, and then log in.
2.4 configure Jenkins
Go to Manage Jenkins-> Global Tool Configuration, and configure the JDK, Git, and Maven paths in turn.
2.4.1 View JDK path
The software installed with yum will not help us configure the environment variables, and you will not see the path directly using the command echo $JAVA_HOME.
First view the path with the following command:
Which java
What you see is / usr/bin/java, but it's really just a soft connection, not the real directory where JDK is located.
Continue to view using the following command:
Ls-l / usr/bin/java
Seeing that / usr/bin/java points to / etc/alternatives/java, unfortunately, it's not the real path we're looking for.
Continue to track:
Ls-l / etc/alternatives/java
The result points to / usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java, and different versions of JDK may have different directory names, which is where JDK really is.
In the same way, you can get the path of Maven.
2.4.2 install and configure plug-ins
Go to Manage Jenkins-> Manage Plugins, and search for and install the Publish Over SSH and Maven Integration plug-ins. The Git Plugins plug-in has been installed by default, so we don't need to install it again.
Configure SSH password-free login
Before configuring the plug-in, let's generate a key pair on the Jenkins server. Run the following command to switch to the jenkins user:
Sudo su jenkins
If you can't switch, open the / etc/passwd file, find the line jenkins, and change / bin/fasle to / bin/bash.
After the switch is successful, the user name of the command prompt may be bash-4.2 $. If you want to display the user name normally, switch back to the root user and do the following:
Edit the file vi ~ / .bash_profile
Add the statement export PS1=' [ubih W] & dollar;'
Effective immediately source ~ / .bash_profile
Then switch to the jenkins user, and the display will be normal. Next, run the following command to generate the key pair:
Ssh-keygen-t rsa
Press enter all the way, and two files, id_rsa and id_rsa.pub, will be generated in the / var/lib/jenkins/.ssh/ directory.
Append the contents of the id_rsa.pub file to the end of the / root/.ssh/authorized_keys file on the application server, one key per line, note that it is the application server. Restart the ssh service on the application server:
Systemctl restart sshd.service
Now that Jenkins can log in to the application server without a password, run the command as jenkins to test it:
Ssh root@
There will be a confirmation prompt for the first connection, just enter yes. This step is very important, if the first time there is no manual connection confirmation, the Jenkins will not be connected.
Configure the Public over SSH plug-in
Enter Manage Jenkins-> Configure System and fill in the Publish over SSH settings.
Path to key: fill in the path to the id_rsa key file that you just generated.
Name: service name, please feel free to fill in.
HostName: IP address or domain name of the application server.
Username: the user's identity to log in to the application server.
Remote Directory: remote directory, the directory where the application is stored on the application server. Jenkins will copy the application to this directory. Make sure this directory exists.
Save~
3. Deploy the Maven project
Click New Item to create a new task, enter the task name at will, and select Maven project, ok.
In General, check Discard old builds to set the maximum number of days to retain build files and the maximum number of build files, otherwise the files generated by each build will be retained and take up disk space.
Configure the remote code repository address from which Jenkins pulls the code. Note here that if the prompt cannot read the warehouse, it may be:
The public key is not added to the authorized_keys file of the remote code server. The above configuration SSH login-free is Jenkins access to the application server, and the Jenkins access code server also needs to be configured, unless the application server and the code server are on the same machine. If you use a code hosting platform such as Code Cloud or GitHub, there will be a corresponding SSH key settings page. The public key has been added to the appropriate file, but not manually connected for the first time. The solution is simple: manually clone the warehouse as a jenkins user and confirm the yes.
Check Add timestamps to the Console Output to output the build process in the console.
Fill in the Maven packaging instructions, and-DMaven.test.skip=true means to skip the test.
Check Run only if build succeeds and select Send files or execute commands over SSH.
The next step is to copy the jar package from the Jenkins server to the application server and run it after setting up the build.
Name: select the service you created earlier.
The jar package generated after Source files:maven packaging, that is, the program to be copied to the application server, can be filled in more than one, separated by commas.
Remove prefix: ignore the prefix, we only need to copy the jar package under target, and we don't need to generate the target directory on the application server.
Remote directory: the destination folder, which inherits the global settings, such as copying the jar package to the / usr/local/app/demo directory here.
Exec command: a command or script executed on the application server after the copy is complete.
Save-> build now. After the construction is successful, open a browser and visit your site.
4. Summary
In fact, the whole process is not very complicated. Jenkins replaces the code from the remote code library-> calls the maven instruction to package the project-> Jenkins copies the packaged file to the remote application server-> executes the shell instruction on the remote application server and starts the program. The two remote operations of Jenkins are done through SSH.
It is more convenient to install Jenkins and Java through yum, but it is relatively troublesome to configure it. You have to find the installation path yourself, and you need to use the jenkins user identity instead of root when configuring SSH. It is freer if you decompress the package.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.