Table of contents
foreword
服务器:CentOS 7.9 64位
jdk:1.8
maven:3.9.1
git:git version 1.8.3.1
jenkins:2.346.3
1. Install jdk
1. Download the rpm installation package of jdk (select the corresponding version according to your operating system), upload it to the server, and execute the yum install jdk-8u301-linux-x64.rpm –y command.
2. Execute the java -version command to verify, if the jdk version number appears, it means the installation is successful.
Two, install maven
1. Download the apache-maven-3.9.1-bin.tar.gz installation package, and execute the command tar –xzvf apache-maven-3.9.1-bin.tar.gz in a non-root directory .
2. Execute the vim /etc/profile command and add the maven configuration to the opened file:
MAVEN_HOME=/home/maven/apache-maven-3.9.1 PATH=${PATH}:${MAVEN_HOME}/bin
After configuration, execute the command source /etc/profile to make the configuration take effect.
3. Execute the mvn -version command to verify that the maven version number appears, indicating that the installation is successful.
3. Install git
1. Configure the yum source and execute the yum install git command.
2. Execute the git -version command to verify, if the git version number appears, the installation is successful.
Fourth, install jenkins
1. Download the rpm package of jenkins and execute the yum install jenkins-2.346.3-1.1.noarch.rpm command.
2. Execute the vim /etc/sysconfig/jenkins command to modify the jenkins configuration. The directory and port can be customized:
3. Start jenkins:
Start command: systemctl start jenkins.service
Stop command: systemctl stop jenkins.service
Restart command: systemctl restart jenkins.service
View command: systemctl status jenkins.service
Five, visit jenkins
1. Use the http://ip: port to access jenkins after startup.
copy admin password
[root@localhost ROOT]# cat /root/.jenkins/secrets/initialAdminPassword 83ebb23eb14446ab9afae6a022b8f728
2. Install the recommended plug-ins:
3. Use admin to continue the operation
4. Complete the installation
6. Create a user
1. Create a new user jenkins, and create a new jenkins user under the system management-management user menu:
For jenkins installed by yum, the jenkins user cannot be switched by default. Both jenkins running and executing scripts are executed by the jenkins user, so it is necessary to ensure that the jenkins user can execute the script in the configuration. For example, to call java, mvn, git and password-free, you must ensure that jenkins users can.
vim /etc/passwd
Change /bin/false to /bin/bash above
Execute su jenkins to switch to the jenkins user
cd to enter the root directory of the current user, and the default root directory of the jenkins user is /var/lib/jenkins.
Seven, configure jenkins
Global Tool Configuration
jdk
maven
Secret free between servers:
To log in without password, you need to switch to the jenkins user and enter the root directory of the jenkins user.
Execute ssh-keygen -t rsa //Generate secret key
Execute ssh-copy-id -i ~/.ssh/id_rsa.pub user name@server IP //Secret-free with the following server, you need to enter the password for the first time
install plugin
Publish over SSH: Publish over SSH
configuration system
git data source
The password is the password set when generating the key without secret. If no password is set, then enter the generated key into the key
Maven project packaging, new item
Configure the newly created item
source code management
configure compile
Publish, deploy
The script can also be directly placed in the Exec command, as follows
echo "Stop Procedure : server-admin.jar" #获取指定项目运行pid pid=`ps -ef |grep java|grep server-admin.jar | grep -v grep |awk '{print $2}'` echo 'old Procedure pid:'$pid #pid存在则kill if [ -n "$pid" ] then kill -9 $pid fi echo 'Start the program : server-admin.jar' #给项目jar 777权限 #进入项目所在目录 cd /mnt/java chmod 777 /mnt/java/server-admin.jar echo '-------Starting-------' #运行项目 (指定时区 指定字符编码 指定输出日志) nohup java -jar server-admin.jar 2>&1 & echo 'end'
8. Execution
If the execution log is success, the packaging, publishing, and deployment are successful
Summarize
The configuration process requires patience, and you need to pay attention to whether the versions of jdk and jenkins are compatible.