背景介绍:
现在有一套我运维的应用系统打算要进行容器化改造工作,这套应用系统包含如下组件:
nginx : 负责发布前端页面
jar包: 项目后台程序
redis: 负责缓存工作
mysql: 数据库存储数据(数据库不容器化)
需要使用的技术:
jenkins gitlib harbor docker
1.安装docker
## 停掉防火墙
systemctl stop firewalld
systemctl disable firewalld
##获取外网权限
export http_proxy=http://这个找自己家网络工程师要
export https_proxy=http://这个找自己家网络工程师要
##移除本身的源
rm -fr /etc/yum.repos.d/*
#添加网易镜像站
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
#添加epel源
cat <<efo>/etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
efo
## 移除已有docker 相关包
yum remove docker-common docker-selinux docker-engine docker -y
## 安装 yum-utils 用于配置
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
## 关闭 edge 和 testing 镜像仓库: 默认应该是禁用的
yum-config-manager --disable docker-ce-edge
yum-config-manager --disable docker-ce-testing
yum makecache
## 如果已经配置了阿里云镜像,上述配置镜像步骤可省略
yum install docker-ce-18.06.3.ce -y
mkdir /etc/docker -p
##在启动前使用自己的docker源(公司可以自建或用阿里的docker加速器)及更改存储位置
cat <<efo>/etc/docker/daemon.json
{
用自己的
}
efo
##启动docker
systemctl enable docker
systemctl start docker
##登录镜像仓库自己公司的登陆后就可以拉取镜像了
docker login -u admin --password x.x.x.x www.badu.com.cn
#docker-enter安装
cat <<efo>/bin/docker-enter
#!/bin/sh
docker_in(){
NAME_ID=\$1
PID=\$(docker inspect -f "{{ .State.Pid }}" \$NAME_ID)
nsenter -t \$PID -m -u -i -n -p
}
main(){
docker_in \$*
}
main \$*
efo
#给文件授予可执行权限
chmod +x /bin/docker-enter
docker 安装完成后使用jenkins流水线发版