Question: The DevOps team was looking for a solution where they want to restart Apache service on all app servers in case the deployment goes fine on these servers in Stratos Datacenter. After having discussion they came up with a solution to use Jenkins chained builds so that they can use a downstream job for services which should only be triggered by the deployment job. So as per the requirements mentioned below configure the required Jenkins jobs.
Click on the + button in the top left corner and select option Select port to view on Host 1, enter port 8081 and click on Display Port. You should be able to access the Jenkins login page. Login using username theadmin and Adm!n321 password.
In the same way you can access Gitea UI on port 8000 and username and password for Git is sarah and Sarah_pass123 respectively. There under user sarah you will find a repository named web which is already cloned on Storage server under sarah's home. sarah is a developer who is working on this repository.
Apache is already installed and configured on all app server so no changes are needed there. The doc root /var/www/html on all these app servers is a NFS shared mount so any data you keep on the Storage server under /data should reflect on all apps.
Create a Jenkins job named nautilus-app-deployment and configure it in a way that if anyone pushes any new change to the origin repository on master branch then the job should auto build and deploy the latest code on Storage server under /data directory. Since /data on Storage server is a NFS mount so changes should auto reflect on all apps.
Create another Jenkins job named manage-services and make it a downstream job for nautilus-app-deployment job. Things to take care about this job:
a. This job should restart httpd service on all app servers.
b. Trigger this job only if the upstream job i.e nautilus-app-deployment is stable.
SSH into Storage Server using sarah user credentials mentioned above. Under sarah user's home you will find a cloned Git repository named web. Under this repository there is an index.html file, update its content to Welcome to the xFusionCorp Industries and then push the changes to the origin into master branch. This push must trigger your Jenkins job and the latest changes must be deployed.
LB server is already configured. Click on the + button in the top left corner and select option Select port to view on Host 1, enter port 80 and click on Display Port. You should be able to see the latest changes you made. Please make sure the required content is loading on the main URL https://<LBR-URL> i.e there should not be a sub-directory like https://<LBR-URL>/web etc.
Note:
You might need to install some plugins and restart Jenkins service. So, we recommend clicking on Restart Jenkins when installation is complete and no jobs are running on plugin installation/update page i.e update centre. Also some times Jenkins UI gets stuck when Jenkins service restarts in the back end so in such case please make sure to refresh the UI page.
Make sure Jenkins job passes even on repetitive runs as validation may try to build the job multiple times.
Deployment related tasks should be done by sudo user on the destination server to avoid any permission issues so make sure to configure your Jenkins job accordingly.
For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.
This task is based on web UI, you can refer below Video Solution for better understanding
Solution:
1. Click on the + button in the top left corner and select option Select port to view on Host 1, enter port 8081 and click on Display Port. You should be able to access the Jenkins login page. Login using username theadmin and Adm!n321 password.
2. Click Jenkins > Manage Jenkins > Manage Plugins and click Available tab.
Search for Gitea, Build Authorization Token Root, SSH & publish over SSH plugin and click Download now and install after restart
3. Create credentials for Sarah, tony, steve, and banner as shown below
4. Create SSH remote hosts/ssh sites under configuration for all the app servers

5. Configure Publish Over SSH for storage server
6. Create a new Jenkins Upstream Build Job
Note down the Jenkins URL to create a Webhook in Gitea
https://2886795296-8081-kitek06o.environments.katacoda.com/buildByToken/build?job=nautilus-app-deployment&token=KODEKLOUDENGINEER
( https://2886795296-8081-kitek06o.environments.katacoda.com will be your Jenkins browser URL )
Refer Below Video for better clarity
or
Take online support on www.nbtechsupport.co.in
7. Configure the Below settings for Build Triggers
8. Build the Job & check the Console output for successful completion
9. Login using the GITEA user and password given in the task (Sarah) Select port to view on Host 1 and connect to port 8000.
10. Add Webook in Gitea the URL which generated in Jenkins Build Triggers
11. Click the webhook & Test delivery to check the hook works.
12. Now Create a new Jenkins Downstream Build Job
13. Under Build Triggers click Build after other projects are builds.
14. Under Build use below remote shell script on the remote host for all app servers
echo Ir0nM@n | sudo -S systemctl restart
httpd && systemctl status httpd echo Am3ric@ | sudo -S systemctl restart httpd && systemctl status httpd echo BigGr33n | sudo -S systemctl restart httpd && systemctl status httpd |
Note - Repate the above 14 step for rest other stapp02 & stapp03 servers & Save
15 .Build the Job & check the Console output for succesful completion
16. Login on storage server by user sarah & commit the index files
thor@jump_host
/$ ssh sarah@ststor01 The authenticity
of host 'ststor01 (172.16.238.15)' can't be established. ECDSA key
fingerprint is SHA256:SySamszyWhhLGFiybhGBqfrr8g55wS/3e37ZpBOvICs. ECDSA key
fingerprint is MD5:6d:31:18:2a:f9:07:f3:29:dd:0a:d3:1f:6e:04:0a:db. Are you sure you
want to continue connecting (yes/no)? yes Warning:
Permanently added 'ststor01,172.16.238.15' (ECDSA) to the list of known
hosts. sarah@ststor01's
password: [sarah@ststor01 ~]$ ll /data total 4 -rw-rw-r-- 1 natasha natasha 8 Jun 15 12:06 index.html [sarah@ststor01 ~]$ [sarah@ststor01 ~]$ cat /data/index.html
Welcome [sarah@ststor01
~]$ cd /home/sarah/web/ .git/ index.html [sarah@ststor01 web]$ git status # On branch
master nothing to
commit, working directory clean [sarah@ststor01
web]$ [sarah@ststor01
web]$ cat index.html Welcome [sarah@ststor01
web]$ vi index.html [sarah@ststor01
web]$ git add index.html [sarah@ststor01
web]$ git commit -m "update" [master 6844347]
update 1 file changed, 1 insertion(+), 1
deletion(-) [sarah@ststor01
web]$ git push origin master Counting
objects: 5, done. Writing objects:
100% (3/3), 281 bytes | 0 bytes/s, done. Total 3 (delta
0), reused 0 (delta 0) remote: .
Processing 1 references remote:
Processed 1 references in total To
http://sarah:Sarah_pass123@git.stratos.xfusioncorp.com/sarah/web.git 18154a0..6844347 master -> master [sarah@ststor01
web]$ [sarah@ststor01
web]$ cat /data/index.html Welcome to the xFusionCorp Industries [sarah@ststor01
web]$ |
17. Validate the task by Click on the + button in the top left corner and select the option Select port to view on Host 1, enter port 80 and click on Display Port. You should be able to see the latest changes you made.
18. Click on Finish & Confirm to complete the task successfully
Happy Learning!!!!
2 Comments
what is password for sarah@ststor01
ReplyDeleteIts in question itself . Password is Sarah_pass123
Delete