[docker installation of jenkins and common problems] super detailed! ! !

Detailed explanation

mkdir D:\liuqinchong\jenkins   # 新建Jenkins工作目录,用于跟容器中Jenkins目录挂在
docker pull jenkins/jenkins:lts  # 拉取Jenkins镜像

#下方命令在windows中可不用
ls -nd /home/Jenkins  # 查看目录归属ID
chown -R 1000:1000 /home/jenkins  # 赋予权限

1. Solve the permission error:

Because the user in the Jenkins container is Jenkins, but the host user is not Jenkins, even root will report an error: /var/jenkins_home/copy_reference_file.log: Permission denied. At this time, you need to assign the host address on the host to access the Jenkins container. Permissions, Jenkins internally uses user with uid 1000

2. Common commands for creating containers with docker:

docker run -dt --name jenkins -p 9090:8080 -p 50000:50000 --privileged=true -v D:\liuqinchong\jenkins:/var/jenkins_home jenkins/jenkins:lts   # 运行Jenkins容器

-privileged=true: Let the container have root privileges, easy to enter the container

-p 9090:8080: Specifies that port 9090 of the host is mapped to port 8080 of the Jenkins container (Jenkins' web access port)

-v D:\liuqinchong\jenkins:/var/jenkins_home: The container /var/jenkins_home path is mounted to the host machine D:\liuqinchong\jenkins path (my host machine here is windows)

docker ps #用于查看容器列表
docker exec -it jenkins /bin/bash #进入容器,可使用容器名称,也可以使用容器id进入

3. Configuration source

Before opening Jenkins, you can replace the source of the official website
. Find the jenkins working directory and open the file hudson.model.UpdateCenter.xml

vim /var/jenkins_home/hudson.model.UpdateCenter.xml
docker restart jenkins  #重启Jenkins

Modify the content in the red box to https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
insert image description here

4. Open Jenkins and install the plugin:

Use the container ip plus port to open Jenkins (commands such as ifconfig cannot be used in the container, it needs to be installed separately)
insert image description here
choose to install the recommended plug-in (because the mirror source is not configured, the download process is slow)
insert image description here
insert image description here
you can use the following command to replace the url

cd /var/jenkins_home/updates #进入容器并切换到updates目录
sed -i 's#https://updates.jenkins.io/download#https://mirrors.huaweicloud.com/jenkins#g' default.json && sed -i 's#http://www.google.com#https://www.baidu.com#g' default.json  #替换url

Then refresh the plug-in download page above, click Continue
insert image description here
insert image description here

5. Jenkins environment configuration

1) Install common commands

docker exec -it -u root 容器id /bin/bash #进入容器
cat /etc/issue #查看当前操作系统

The container may not have some common commands and needs to be downloaded

apt-get install -y vim

insert image description here
If the above problems occur, use the following command to update apt-get. The update process may be slow. After the update is complete, you can use the apt-get command to install again.

Note: There may also be problems with no permissions
insert image description here

Solution:

docker exec -it -u root jenkins /bin/bash  #指定root用户进入
#删除提示的两个文件
rm -rf /var/lib/dpkg/lock
rm -rf /var/cache/apt/archives/lock

passwd root #给root设置密码,下次无权限时可直接切换root用户
apt-get update

2) apt configuration Alibaba cloud source

The process may be slow, you can modify the apt configuration to add Alibaba Cloud source

# 修改 apt-get 源的配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份
echo > /etc/apt/sources.list #清空源
cat /etc/apt/sources.list #查看是否清空
#向/etc/apt/sources.list文件中,写入源地址
echo  "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free" >/etc/apt/sources.list
echo  "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free" >>/etc/apt/sources.list
echo  "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free" >>/etc/apt/sources.list
echo  "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free" >>/etc/apt/sources.list
apt-get update #更新

3) Common commands for apt-get installation:

install yum

apt-get update && apt-get install yum

bash: ip: command not found

apt-get update && apt-get install -y iproute2

bash: ping: command not found

apt-get update && apt install iputils-ping

bash: ifconfig: command not found

apt-get update && apt install net-tools

bash: vi: command not found

apt-get update &&  apt-get install vim

bash: route: command not found

apt-get update && apt-get install -y iproute2 && apt-get update && apt install net-tools

bash: netstat: command not found

apt-get update && apt install net-tools

bash: ps: command not found

apt-get update && apt-get install procps

bash: top: command not found

apt-get update && apt-get install procps

6. Configure the Python3 environment

1) Install python3 in the Jenkins container

There is no Python3 environment in the Jenkins container, you need to install it yourself:

Note: For Ubuntu system, use apt-get instead of yum here.
It is recommended to use the aptitude install command to install the following tools to effectively resolve dependencies. See below for a detailed explanation. apt-get install and aptitude install can be replaced with each other

apt install aptitude #安装aptitude

#apt-get安装依赖包
aptitude -y install gcc automake autoconf libtool make
aptitude -y install make*
aptitude -y install zlib*
aptitude -y install openssl libssl-dev
aptitude install sudo

# 安装Python3
cd /var/jenkins_home
mkdir python3
cd python3
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz # 获取python-3.6.8.tgz包
tar -xvf Pyhthon-3.6.8.tgz #解压
cd Python-3.6.8 # 切换到Python-3.6.8目录

#执行make和make install安装
./configure --prefix=/var/jenkins_home/python3 --with-ssl
make
make install

# 添加软连接
# 添加Python3软连接
ln -s /var/jenkins_home/python3/bin/python3.6 /usr/bin/python3
# 添加pip3软连接
ln -s /var/jenkins_home/python3/bin/pip3 /usr/bin/pip3

# 安装所需Python库
pip3 instal requests pytest-html pytest

2) Common solutions to problems encountered during installation:

There may be an error message during installation
insert image description here

Solution 1. Use aptitude to install (recommended):

使用aptitude,aptitude与 apt-get 一样,是 Debian 及其衍生系统中功能极其强大的包管理工具。
与 apt-get 不同的是,aptitude在处理依赖问题上更佳一些。
举例来说,aptitude在删除一个包时,会同时删除本身所依赖的包。
这样,系统中不会残留无用的包,整个系统更为干净。此处不做赘述。
apt install aptitude #安装aptitude

有的问题 apt-get 解决不了,必须使用 aptitude 解决,有的问题,用 aptitude 解决不了,必须使用apt-get.

aptitude 解决得更好的地方: install, remove, reinstall(apt-get无此功能), show(apt-get无此功能), search(apt-get无此功能), hold(apt-get无此功能), unhold(apt-get无此功能),

apt-get 解决得更好的地方: source(aptitude无此功能), build-dep (低版本的aptitude没有build-dep功能)

apt-get 跟 aptitude 没什么区别的地方:update, upgrade (apt-get upgrade=aptitude safe-upgrade, apt-get dist-upgrade=aptitude full-upgrgade)
sudo aptitude install 

Option 2. Use yum to install:

安装配置yum,上方已经安装好yum,接下来配置源

由于是Ubuntu没有yum源,所以要想使用yum安装软件必须要配置yum安装源。
在/etc/yum/repos.d/目录下创建两个文件,fedora-163.repo和fedora-updates-163.repo。
分别复制以下配置信息保存即可。

fedora-163.repo configures the following information

[fedora]
 
name=Fedora 17 - $basearch - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/releases/17/Everything/$basearch/os/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-17&arch=$basearch
enabled=1
metadata_expire=7d
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
 
[fedora-debuginfo]
name=Fedora 17 - $basearch - Debug - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/releases/17/Everything/$basearch/debug/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-debug-17&arch=$basearch
enabled=0
metadata_expire=7d 
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
 
[fedora-source]
name=Fedora 17 - Source - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/releases/17/Everything/source/SRPMS/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-source-17&arch=$basearch
enabled=0
metadata_expire=7d
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

fedora-updates-163.repo configuration information is as follows

[updates]
name=Fedora 17 - $basearch - Updates - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/updates/17/$basearch/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f17&arch=$basearch
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
 
[updates-debuginfo]
name=Fedora 17 - $basearch - Updates - Debug - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/updates/17/$basearch/debug/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-debug-f17&arch=$basearch
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

[updates-source]
name=Fedora 17 - Updates Source - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/updates/17/SRPMS/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-source-f17&arch=$basearch
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

last execution

yum makecache

Guess you like

Origin blog.csdn.net/m0_43550804/article/details/129600512