“Useradd与adduser的区别”与“Using Jenkins agents with docker”:页面之间的差异

来自linuxsa wiki
(页面间差异)
跳转到导航 跳转到搜索
Evan留言 | 贡献
导入1个版本
 
Evan留言 | 贡献
 
第1行: 第1行:
=区别=
[[category:devops]]
=Configuring agents with Docker=
 
==info==
Jenkins 2.289.3 LTS
 
== ** Generating an SSH key pair        ==                                             
                                                                                     
    ssh-keygen    -t dsa -f ~/.ssh/jenkins_agent_key
 
==*** Create a Jenkins SSH credential    ==                                           
<pre>                                                                                   
        1. Go to your Jenkins dashboard;                                               
                                                                                     
        2.Go to Manage Jenkins option in main menu and click on credentials button;   
        3.select the drop option Add Credentials from the global item;               
                                                                                     
    4.Fill the form:                                                                 
                                                                                     
        Kind: SSH Username with private key;                                       
                                                                                     
        id: jenkins                                                                 
                                                                                     
        description: The jenkins ssh key                                           
                                                                                     
        username: jenkins                                                           
                                                                                     
        Private Key: select Enter directly and press the Add button to insert your 
        private key from ~/.ssh/jenkins_agent_key                                   
                                                                                     
        Passphrase: fill your passphrase used to generate the SSH key pair and then 
        press OK  </pre>
 
==**  Creating your Docker agent    ==                                                 
<pre>    run the command to start your first agent:                                     
                                                                                     
    docker run -d --rm --name=agent1 -p 22:22 \                                     
    -e "JENKINS_AGENT_SSH_PUBKEY=[your-public-key]" \                               
    jenkins/ssh-agent:alpine                                                       
                                                                                     
                                                                                     
                                                                                     
    实际替换上你的pub key                                                           
    docker run -d --rm --name=agent1 -p 222:22 \                                   
    -e "JENKINS_AGENT_SSH_PUBKEY=ssh-rsa                                           
    AAAAB3NzaC1yc2EAAAADAQABAAABAQCljcroCTtT+Qipw8NvncMZx731Dv4fjZPt09JaD+aR3jdNWp5e\
    bpKJQGD12UzN6/2lRPHipIroY/WKt+MIy9y+0iQ1Om+nl01j6GHkVeGVhoKCmv4dRQgvoczYHO5ccXNo\
    uVeTnopg+4UiKWzimOVE0pcu06H//OFEGR24BT8bBAHrV17EYshhY09I9LXzw8O+oSsn217frmNNEfUo\
    aq72verbEUrPS/NfBwdb4W4Pfdc874bUcnt7UEFa9VSSeLFa0Xp7xzNurZye+m9WAn/WhjDXQJgZE3Ql\
    yYLc6ZT9k4EdXlJgF/GeZ4wX4p9itnmimMiYy+eieb4jwHlAWryh root@gitlabzbx             
    " \                                                                             
    jenkins/ssh-agent:alpine                                                       
                                                                                     
    Now run the following command to update the container environment:             
                                                                                     
    $ VARS1="HOME=|USER=|MAIL=|LC_ALL=|LS_COLORS=|LANG="                           
    $ VARS2="HOSTNAME=|PWD=|TERM=|SHLVL=|LANGUAGE=|_="                             
    $ VARS="${VARS1}|${VARS2}"                                                     
    $ docker exec agent1 sh -c "env | egrep -v '^(${VARS})' >> /etc/environment"      </pre>
 
 
 
 
=* config on web =                                                                   
<pre>  Setup up the agent1 on jenkins.                                                   
                                                                                     
      1. Go to your Jenkins dashboard;                                                 
                                                                                     
      2. Go to Manage Jenkins option in main menu;                                     
                                                                                     
      3.Go to Manage Nodes and clouds item;                                           
 
 
 
4.Go to New Node option in side menu;
 
5.Fill the Node/agent name and select the type; (e.g. Name: agent1, Type: Permanent Agent)
 
6.Now fill the fields:
 
    Remote root directory; (e.g.: /home/jenkins )
 
    label; (e.g.: agent1 )
 
    usage; (e.g.: only build jobs with label expression…​)
 
    Launch method; (e.g.: Launch agents by SSH )
 
        Host; (e.g.: localhost or your IP address 一般是ip 不可能是自己机器 )
 
        Credentials; (e.g.: jenkins )
 
        Host Key verification Strategy; (e.g.: Manually trusted key verification …​ ) 
 
 
自己要注意的细节 因为母机的22不能再用了                                                                                   
    固定 --                                                                         
                                                                                     
  ssh 端口 222                                                                     
 
 
 
Now press the button Launch agent and wait some seconds, then you should receive
the message: Agent successfully connected and online on the last log line.
 
Agent successfully connected
                                                                                   
                                                                                     
                                                                                     
  然后启动节点                                                                     
                                                                                     
  如果遇到报错【The SSH key for this host is not currently trusted. Connections     
  will be denied until this new key is authorised.】                               
                                                                                     
                                                                                     
                                                                                     
  直接节点配置里面点trust key                                                       
                                                                                     
  agent1                                                                           
  Trust SSH Host Key                                                               
                                                                                     
  :~/tmp$ ssh  -i id_rsa  -p 222 jenkins@192.168.88.149                             
                                                                                     
  我测试是可以login的呀    </pre>
 
=trouble shooting=
<pre>
java.io.IOException: Java not found on hudson.slaves.SlaveComputer@d48b725. Install Java 8 or Java 11 on the Agent.
alpine 安装java
 
apk add openjdk8
 
java目录
 
/opt/java/openjdk/bin/java
 
要安装这个插件
SSH Agent
 
SSH build Agents
 
这两个搞得有点久
 
/home/jenkins  工作目录改成这个 /tmp好了 ? 不是的
 
 
Node and Label parameter    nodelabelparameter
Job Restrictions  插件  不然
I can't find “Restrict where this project can be run” in the configure page
 
 
就是手工添加的了 有如当年在xk 选择git 版本一样
参数化构建过程  -->添加参数 ->Node -->
 
 
https://plugins.jenkins.io/nodelabelparameter/
 
docker pull jenkins/ssh-slave
 
 
把php 搞到 agent  agent1 还要上 apk add git  phing 和 相关dns  root运行哦
 
</pre>
 
=测试一下 Delegating the first job to agent1=
<pre>
<pre>
useradd与adduser都是创建新的用户


在RHEL下useradd与adduser是没有区别的都是在创建用户,在home下自动创建目录,没有设置密码,需要使用passwd命令修改密码。


而在debian系列下 下useradd与adduser有所不同
Go to your jenkins dashboard;
 
Select New Item on side menu;


1、useradd在使用该命令创建用户是不会在/home下自动创建与用户名同名的用户目录,而且不会自动选择shell版本,也没有设置密码,那么这个用户是不能登录的,需要使用passwd命令修改密码。
Enter a name. (e.g.: First Job to Agent1)


2、adduser在使用该命令创建用户是会在/home下自动创建与用户名同名的用户目录,系统shell版本,会在创建时会提示输入密码,更加友好。
Select the Freestyle project and press OK;


userdel 删除用户,
#我暂时没这个选项 why
Check the option: Restrict where this project can be run;


userdel只能删除用户,并不会删除相关的目录文件。userdel -r 可以删除用户及相关目录。</pre>
Fill the field: label with the agent1 label; (e.g.: agent1)
</pre>


=useradd=
==agent jar形式运行==
<pre>
<pre>
#常用例子
系统配置:
useradd  eva -m  -s /bin/bash  -g evan
 
新建节点:
 
如果报“从节点端口被禁用”点击“配置连接”或 系统管理->全局安全配置


useradd user1 -m -s /bin/bash -g users
然后根据页面提示到slave节点进行如下操作:


useradd : Adds new user to linux.
下载agent:
user1 : After the useradd command you need to specify the user name that you want to create.
wget https://jenkins.chexiangsit.com/jnlpJars/agent.jar
-m : It creates Home directory for new user.
-s /bin/bash : It creates bash shell.This is the default shell for all the Linux distributions.
-g users : This is the default group that newly created user will be member of.


运行agent:
nohup java -jar agent.jar -jnlpUrl http://10.32.221.8:8080/computer/node1/slave-agent.jnlp -secret 8410d288284123c57bff988f693f64dc0d388e5fcefcebef8675196f288c947e -workDir "/opt/jenkins" &
</pre>
</pre>
[[category:linux]]
 
=see also=       
[https://www.jenkins.io/doc/book/using/using-agents/ 官网Using Jenkins agents]
 
 
[https://blog.csdn.net/weixin_36938307/article/details/105577769  使用Docker Plugin动态生成Jenkins Slave运行流水线]
 
[https://www.cnblogs.com/yickel/p/12206838.html Jenkins学习(3)-Jenkins的Master/Slave机制,及添加Slave节点操作]
 
[https://devopscube.com/docker-containers-as-build-slaves-jenkins/ How to Setup Docker Containers as Build Agents for Jenkins]
 
[https://blog.csdn.net/IT_YUAN/article/details/80515085  Jenkins : 安装 master 和 slave]
 
[https://cloud.tencent.com/developer/article/1698609 Jenkins增加节点的两种方式]
 
 
注意 下面这些是老的版本啦  不能用
 
https://blog.csdn.net/qq_31977125/article/details/82999872

2021年8月8日 (日) 03:55的最新版本

Configuring agents with Docker

info

Jenkins 2.289.3 LTS

** Generating an SSH key pair

    ssh-keygen    -t dsa -f ~/.ssh/jenkins_agent_key

*** Create a Jenkins SSH credential

                                                                                     
        1. Go to your Jenkins dashboard;                                                
                                                                                      
         2.Go to Manage Jenkins option in main menu and click on credentials button;    
         3.select the drop option Add Credentials from the global item;                 
                                                                                      
     4.Fill the form:                                                                   
                                                                                      
         Kind: SSH Username with private key;                                         
                                                                                      
         id: jenkins                                                                  
                                                                                      
         description: The jenkins ssh key                                             
                                                                                      
         username: jenkins                                                            
                                                                                      
         Private Key: select Enter directly and press the Add button to insert your   
         private key from ~/.ssh/jenkins_agent_key                                    
                                                                                      
         Passphrase: fill your passphrase used to generate the SSH key pair and then  
         press OK   

** Creating your Docker agent

    run the command to start your first agent:                                       
                                                                                      
     docker run -d --rm --name=agent1 -p 22:22 \                                      
     -e "JENKINS_AGENT_SSH_PUBKEY=[your-public-key]" \                                
     jenkins/ssh-agent:alpine                                                         
                                                                                      
                                                                                      
                                                                                      
     实际替换上你的pub key                                                            
     docker run -d --rm --name=agent1 -p 222:22 \                                     
     -e "JENKINS_AGENT_SSH_PUBKEY=ssh-rsa                                             
     AAAAB3NzaC1yc2EAAAADAQABAAABAQCljcroCTtT+Qipw8NvncMZx731Dv4fjZPt09JaD+aR3jdNWp5e\
     bpKJQGD12UzN6/2lRPHipIroY/WKt+MIy9y+0iQ1Om+nl01j6GHkVeGVhoKCmv4dRQgvoczYHO5ccXNo\
     uVeTnopg+4UiKWzimOVE0pcu06H//OFEGR24BT8bBAHrV17EYshhY09I9LXzw8O+oSsn217frmNNEfUo\
     aq72verbEUrPS/NfBwdb4W4Pfdc874bUcnt7UEFa9VSSeLFa0Xp7xzNurZye+m9WAn/WhjDXQJgZE3Ql\
     yYLc6ZT9k4EdXlJgF/GeZ4wX4p9itnmimMiYy+eieb4jwHlAWryh root@gitlabzbx              
     " \                                                                              
     jenkins/ssh-agent:alpine                                                         
                                                                                      
     Now run the following command to update the container environment:               
                                                                                      
     $ VARS1="HOME=|USER=|MAIL=|LC_ALL=|LS_COLORS=|LANG="                             
     $ VARS2="HOSTNAME=|PWD=|TERM=|SHLVL=|LANGUAGE=|_="                               
     $ VARS="${VARS1}|${VARS2}"                                                       
     $ docker exec agent1 sh -c "env | egrep -v '^(${VARS})' >> /etc/environment"      



* config on web

   Setup up the agent1 on jenkins.                                                    
                                                                                      
      1. Go to your Jenkins dashboard;                                                  
                                                                                      
      2. Go to Manage Jenkins option in main menu;                                      
                                                                                      
       3.Go to Manage Nodes and clouds item;                                            
 



4.Go to New Node option in side menu;

5.Fill the Node/agent name and select the type; (e.g. Name: agent1, Type: Permanent Agent)

6.Now fill the fields:

    Remote root directory; (e.g.: /home/jenkins )

    label; (e.g.: agent1 )

    usage; (e.g.: only build jobs with label expression…​)

    Launch method; (e.g.: Launch agents by SSH )

        Host; (e.g.: localhost or your IP address 一般是ip 不可能是自己机器 )

        Credentials; (e.g.: jenkins )

        Host Key verification Strategy; (e.g.: Manually trusted key verification …​ )   


自己要注意的细节 因为母机的22不能再用了                                                                                    
    固定 --                                                                           
                                                                                      
   ssh 端口 222                                                                       
 



Now press the button Launch agent and wait some seconds, then you should receive
the message: Agent successfully connected and online on the last log line.

Agent successfully connected
                                                                                     
                                                                                      
                                                                                      
   然后启动节点                                                                       
                                                                                      
   如果遇到报错【The SSH key for this host is not currently trusted. Connections      
   will be denied until this new key is authorised.】                                 
                                                                                      
                                                                                      
                                                                                      
   直接节点配置里面点trust key                                                        
                                                                                      
   agent1                                                                            
   Trust SSH Host Key                                                                 
                                                                                      
   :~/tmp$ ssh  -i id_rsa  -p 222 jenkins@192.168.88.149                              
                                                                                      
   我测试是可以login的呀     

trouble shooting

java.io.IOException: Java not found on hudson.slaves.SlaveComputer@d48b725. Install Java 8 or Java 11 on the Agent.
alpine 安装java 

apk add openjdk8

java目录 

/opt/java/openjdk/bin/java

要安装这个插件 
SSH Agent 

SSH build Agents

这两个搞得有点久 

/home/jenkins  工作目录改成这个 /tmp好了 ? 不是的 


Node and Label parameter    nodelabelparameter
Job Restrictions  插件  不然 
I can't find “Restrict where this project can be run” in the configure page


就是手工添加的了 有如当年在xk 选择git 版本一样
参数化构建过程  -->添加参数 ->Node -->


https://plugins.jenkins.io/nodelabelparameter/

docker pull jenkins/ssh-slave


把php 搞到 agent   agent1 还要上 apk add git  phing 和 相关dns   root运行哦 

测试一下 Delegating the first job to agent1


Go to your jenkins dashboard;

Select New Item on side menu;

Enter a name. (e.g.: First Job to Agent1)

Select the Freestyle project and press OK;

#我暂时没这个选项 why 
Check the option: Restrict where this project can be run;

Fill the field: label with the agent1 label; (e.g.: agent1)

agent jar形式运行

系统配置:

新建节点:

如果报“从节点端口被禁用”点击“配置连接”或 系统管理->全局安全配置

然后根据页面提示到slave节点进行如下操作:

下载agent:
wget https://jenkins.chexiangsit.com/jnlpJars/agent.jar

运行agent:
nohup java -jar agent.jar -jnlpUrl http://10.32.221.8:8080/computer/node1/slave-agent.jnlp -secret 8410d288284123c57bff988f693f64dc0d388e5fcefcebef8675196f288c947e -workDir "/opt/jenkins" &

see also

官网Using Jenkins agents


使用Docker Plugin动态生成Jenkins Slave运行流水线

Jenkins学习(3)-Jenkins的Master/Slave机制,及添加Slave节点操作

How to Setup Docker Containers as Build Agents for Jenkins

Jenkins : 安装 master 和 slave

Jenkins增加节点的两种方式


注意 下面这些是老的版本啦 不能用

https://blog.csdn.net/qq_31977125/article/details/82999872