Tuesday, 2 April 2024

Permanent Agent server using VPS in Jenkins

1. What to use Permanent Agent server for?

- Permanent Agent is a Jenkins agent for deploy (CD) app.

2. How to use Permanent Agent server?

- Install Java in server agent: install java version, setup JAVA_HOME path the same with jenkin master server, example jdk11.0.11, JAVA_HOME=/usr/lib/jvm/..

- Create agent: Mange Jenkins > Manage node and cloud > New node > Node name: Agent1 > Type: checked Permanent Agent > Number of executors: 2 > Remote root directory: /home/jenkins/Agent1 > Labels: Agent1 Linux > Usage: Use this node as much as possible > Launch method: Launch agents via SSH > Disable WorkDir: not checked > Custom WorkDir path: /home/jenkins/ Availability: Keep this agent online as much as possible > Save
+ Number of executors: with Executor is represent a separate process capable of executing a job, ex = 2 => can run 2 jobs same time.
+ Launch agent has two ways:
/ By connecting it to master (also call controller): Agent connect to Jenkins, by run jar file download from jenkins (using when don't want open ssh).
/ Via SSH: Jenkins connect to Agent, by using ssh to agent (using when has ssh on agent): Host: Agent1 > Credentials: (Select existed) || Add new > Domain: Global credentials (unrestricted) > Kind: SSH Username with private key || (Username & Password) > ID: CredentailLinuxAgent > return to select existed Credential already create > Host Key Verification Strategy: None verify verification Strategy. > Click Advanced > Port: 22 (your ssh agent port) 
+ Remote root directory: the path for jenkin create, manage working file...
+ Host key verification Strategy:
/ None verify verification Strategy (just connect, ignore everything)
/ Know hosts file Verification Strategy (need config ssh agent host in known host verification on jenkins master host: go to host master > cd /var/lib/jenkins/ (|| jenkins path docker if you use docker run jenkin: ../laradock/jenkins/jenkins_home) > mkdir -p /var/jenins/.ssh > ssh-keyscan -H Agent1 >> var/lib/jenkins/.ssh/know_hosts (collect ssh key from Agent1 server, after write them to know_hosts file > chow -R jenkins:jenkins /var/lib/jenkins/.ssh).

- Run the permanent Agents:
+ Configure global security: Agent: TCP port for inbound agents: Fixed: 50000
+ Manage nodes and clouds > Click Open the agent > run from agent command line in /home/jenkins (to install java, javac)

- Using the Permanent Agent: Select job/ Configure/ checked Restrict where this project can be run?/ Label Expression: Agent1/ Save/ Build job again/

Reference: Setting up Permanent Agents

3. What does Permanent Agent server include? 

--------------------------
Detailed instructions

References:
- https://www.youtube.com/watch?v=99DddJiH7lM

Thank you.

No comments:

Post a Comment

Golang Advanced Interview Q&A