Jenkins is an open source automation server designed to automate the repetitive technical tasks involved in continuous integration and delivery of software. Jenkins is Java-based and can be installed from the Ubuntu software package, or by downloading and running its web application ARchive (WAR) file-forming a complete collection of web applications, the file is designed to run on the server.
In this tutorial, we will install Jenkins by adding its Debian package repository, and then use that repository to install the package using apt-get
.
To follow this tutorial, you will need:
Since the default update source is slow, modify it to the update source of Alibaba Cloud
vim /etc/apt/sources.list
Clear the contents of the file and add the following:
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu xenial-security main restricted
deb http://mirrors.aliyun.com/ubuntu xenial-security universe
deb http://mirrors.aliyun.com/ubuntu xenial-security multiverse
Officially install java jdk
apt-get update
sudo apt-get install -y openjdk-8-jdk
apt-get clean all
Note: I am using a separate server here to install Jenkins
The version of Jenkins included in the default Ubuntu package often lags behind the latest version of the project itself. In order to take advantage of the latest fixes and features, we will use the package maintained by the project to install Jenkins.
First, we add the repository key to the system.
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
After adding the key, the system will return OK
. Next, we append the Debian package repository address to the server's sources.list
:
echo deb http://pkg.jenkins.io/debian-stable binary/| sudo tee /etc/apt/sources.list.d/jenkins.list
When these two are in place, we will run update
so that apt-get
will use the new repository:
sudo apt-get update
Finally, we will install Jenkins and its dependencies, including Java:
sudo apt-get install -y jenkins
Now that Jenkins and its dependencies are in place, we will start the Jenkins server.
Using systemctl
we will start Jenkins:
sudo systemctl start jenkins
Since systemctl
does not display output, we will use its status
command to verify whether it started successfully:
sudo systemctl status jenkins
If all goes well, the beginning of the output should show that the service is active and configured to start on boot:
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled)
Active: active (exited)since Thursday 2019-08-0820:27:37 CST; 33s ago
Docs: man:systemd-sysv-generator(8)
Now that Jenkins is running, we will adjust the firewall rules so that we can reach Jenkins from a web browser to complete the initial setup.
Please note that the firewall has been turned off, we will use the server domain name or IP address to access Jenkins's default port 8080
:
http://ip_address_or_domain_name:8080
We should see the "Unlock Jenkins" screen showing the location of the initial password
In the terminal window, we will use the cat
command to display the password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
We will copy the 32-character alphanumeric password from the terminal and paste it into the "Administrator Password" field, then click "Continue". The next screen provides options to install suggested plug-ins or select specific plug-ins.
We will click on the "Install suggested plugins" option, which will start the installation process immediately:
After the installation is complete, you will be prompted to set up the first administrative user. You can skip this step and continue with the initial password used above as the admin
, but we will take a moment to create the user.
**Note: **The default Jenkins server is not encrypted, so the data submitted using this form is not protected. When you are ready to use this installation, follow the guide How to configure SSL to Jenkins using Nginx reverse proxy. This will protect user credentials and information about the build sent through the web interface.
Create an admin user, define your own password
Confirm instance configuration
Once the first admin user is in place, you should see a "Jenkins ready!" confirmation screen.
Click "Start using Jenkins" to access the main Jenkins dashboard:
View
root@ubuntu:~# sudo netstat -plntu
Activate Internet connection(Server only)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 000.0.0.0:220.0.0.0:* LISTEN 1020/sshd
tcp6 00:::22:::* LISTEN 1020/sshd
tcp6 00:::8080:::* LISTEN 8944/java
udp 000.0.0.0:680.0.0.0:*928/dhclient
udp6 00:::33848:::*8944/java
udp6 00:::5353:::*8944/java
At this point, Jenkins has been successfully installed.
note:
The default port is 8080, sometimes it needs to be modified as follows due to port occupation:
1 , Check the /etc/init.d/jenkins script, modify the check_tcp_port command of the do_start function, and change the port number from 8080 to 8082:
2 , Modify /etc/default/jenkins file, change port 8080 to 8082
HTTP_PORT=8082
3 , Restart Jenkins
sudo systemctl restart jenkins
In this tutorial, we installed Jenkins using the package provided by the project, started the server, and created an administrative user. At this point, you can start exploring Jenkins.
After completing the exploration, if you decide to continue using Jenkins, please follow the guide, [How to use Nginx reverse proxy to configure Jenkins with SSL,] (http://www.howtoing.com/how-to-configure-jenkins-with-ssl-using-an-nginx-reverse-proxy/) to protect the password and any sensitive system or product information that will be sent on your machine and Plain text between servers.
Reference link for this article:
https://www.jianshu.com/p/845f267aec52
Recommended Posts