First, update the default Ubuntu packages lists for upgrades with the following command:
sudo apt-get updateThen, run the following command to install JDK 11:
sudo apt-get install openjdk-11-jdkNow, we will install Jenkins itself. Issue the following four commands in sequence to initiate the installation from the Jenkins repository:
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkinsOnce that’s done, start the Jenkins service with the following command:
sudo systemctl start jenkins.serviceTo confirm its status, use:
sudo systemctl status jenkinsWith Jenkins installed, we can proceed with adjusting the firewall settings. By default, Jenkins will run on port 8080.
In order to ensure that this port is accessible, we will need to configure the built-in Ubuntu firewall (ufw). To open the 8080 port and enable the firewall, use the following commands:
sudo ufw allow 8080sudo ufw enableOnce done, test whether the firewall is active using this command:
sudo ufw statusWith the firewall configured, it’s time to set up Jenkins itself. Type in the IP of your EC2 along with the port number. The Jenkins setup wizard will open.
To check the initial password, use the cat command as indicated below:
sudo cat /var/lib/jenkins/secrets/initialAdminPasswordAll Set! You can now start automating...
Installing Apache Install Apache from Repo
sudo apt-get update
sudo apt-get install apache2 -yEnable proxy, proxy_http, headers module
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod headersEdit Apache Configuration file
cd /etc/apache2/sites-available/
sudo vim jenkins.confThen, In the file enter the following code snippet to make the Apache works for Jenkins. Then, In this ServerName should be your domain name, ProxyPass should point your localhost point to Jenkins (Port 8080) and ProxyPassReverse should be added for both localhost address and Domain address. In the block, we need to give access to the apache to handle the Jenkins.
<Virtualhost *:80>
ServerName your-domain-name.com
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
<Proxy http://localhost:8080/*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/ nocanon
ProxyPassReverse / http://localhost:8080/
ProxyPassReverse / http://your-domain-name.com/
</Virtualhost>Enable and Restart Jenkins
sudo a2ensite jenkins
sudo systemctl restart apache2
sudo systemctl restart jenkinsConfiguring Firewall
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow httpsNow, enable firewall by passing following command.
ufw enableThat’s all. Now on, your Jenkins server will run behind the Apache’s Reverse Proxy.