0 系统配置
0.1 静态网络配置
0.1.1 查看Network信息
以VMware+CentOS 7为例打开VMware的虚拟网络编辑器,找到类型为NAT模式的Network,点击NAT设置
0.0.2 设置Centos网络
查看Cnetos网络ip addr
编辑配置文件**vi /etc/sysconfig/network-scripts/ifcfg-ens33**
TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=staticDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=ens33UUID=5b21dde1-b451-41e9-ac94-b3aaa329daa4DEVICE=ens33ONBOOT=yesIPADDR=192.168.182.5PREFIX=24GATEWAY=192.168.182.2DNS1=192.168.182.2IPV6_PRIVACY=yesZONE=public
重启网络service network restart
验证网络是否通畅ping www.baidu.com -c 3
1 安装docker
1.1 离线安装
1.1.1 下载地址
https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz
# 解压dockertar -xvf docker-20.10.9.tgz# 移动文件到/usr/bin目录cp docker/* /usr/bin/
1.1.2 docker注册为service
vi /etc/systemd/system/docker.service
将下面的内容拷贝至docker.service文件中
[Unit]Description=Docker Application Container EngineDocumentation=https://docs.docker.comAfter=network-online.target firewalld.serviceWants=network-online.target[Service]Type=notifyExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375ExecReload=/bin/kill -s HUP $MAINPIDLimitNOFILE=infinityLimitNPROC=infinityTimeoutStartSec=0Delegate=yesKillMode=processRestart=on-failureStartLimitBurst=3StartLimitInterval=60s[Install]WantedBy=multi-user.target
1.2.3 启动
# 加文件权限
chmod +x /etc/systemd/system/docker.service
# 重载unit配置文件
systemctl daemon-reload
# 启动Docker
systemctl start docker
# 设置开机自启
systemctl enable docker.service
# 查看docker版本
docker -v
1.2 线上安装
1.2.1 移除以前docker相关包
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
1.2.2 配置yum源
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1.2.3 安装docker
sudo yum install -y docker-ce docker-ce-cli containerd.io
#以下是在安装k8s的时候使用
yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6
1.2.4 修改配置文件
开启远程访问,在ExecStart行添加”tcp://0.0.0.0:2375”配置
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
1.2.5 启动
systemctl enable docker --now
1.3 配置加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://g6xn8hnd.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
2 安装docker-compose
2.1 二进制安装
# github下载
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# github太慢可以用daocloud下载
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 测试安装结果
docker-compose --version
# 卸载
sudo rm /usr/local/bin/docker-compose
2.2 pip安装
sudo pip install docker-compose
2.3 离线安装
下载最新版本后上传服务器:https://github.com/docker/compose/releases/
# 移动到目录
mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
# 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 测试安装结果
docker-compose --version
3 安装harbor
3.1 下载
# 下载
wget https://storage.googleapis.com/harbor-releases/release-2.5.0/harbor-offline-installer-v2.5.0.tgz
# 解压
tar -xvf harbor-offline-installer-v2.5.0.tgz -C /home
3.2、openssl证书
mkdir /home/harbor/ssl
# CA
openssl req \
-newkey rsa:4096 -nodes -sha256 -keyout ca.key \
-x509 -days 365 -out ca.crt \
-subj '/C=CN/ST=Hunan/L=Changsha/O=Ysstech/CN=docker.ysstech.com'
# 签名
openssl req \
-newkey rsa:4096 -nodes -sha256 -keyout harbor.key \
-out harbor.csr \
-subj '/C=CN/ST=Hunan/L=Changsha/O=Ysstech/CN=docker.ysstech.com'
# 生成证书
echo 'subjectAltName = IP:192.168.182.4' > extfile.cnf
openssl x509 -req -days 365 -in harbor.csr \
-CA ca.crt -CAkey ca.key -CAcreateserial \
-extfile extfile.cnf -out harbor.crt
# 客户端证书
openssl x509 -inform PEM -in harbor.crt -out harbor.cert
3.3、配置harbor.yml
cd /home/harbor
cp harbor.yml.tmpl harbor.yml
修改以下内容
hostname: docker.ysstech.com
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 8888
# https related config
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /home/harbor/ssl/harbor.crt
private_key: /home/harbor/ssl/harbor.key
# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: root123
# Harbor DB configuration
database:
# The password for the root user of Harbor DB. Change this before any production use.
password: root123
# The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
max_idle_conns: 100
# The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
# Note: the default number of connections is 1024 for postgres of harbor.
max_open_conns: 900
# The default data volume
data_volume: /home/harbor/data
# Log configurations
log:
# options are debug, info, warning, error, fatal
level: info
# configs for logs in local storage
local:
# Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
rotate_count: 50
# Log files are rotated only if they grow bigger than log_rotate_size bytes. If size is followed by k, the size is assumed to be in kilobytes.
# If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G
# are all valid.
rotate_size: 200M
# The directory on your host that store log
location: /home/harbor/log
3.2 、Docker配置
cd /home/harbor/ssl
# 创建目录并复制证书
mkdir -p /etc/docker/certs.d/docker.ysstech.com
cp harbor.cert /etc/docker/certs.d/docker.ysstech.com
cp harbor.key /etc/docker/certs.d/docker.ysstech.com
cp ca.crt /etc/docker/certs.d/docker.ysstech.com
#重启docker
systemctl restart docker
3.4、启动与停止
# 此命令将会停止 up 命令所启动的容器,并移除网络(慎用)
docker-compose down -v
# 启动
docker-compose up -d
# 停止
docker-compose stop
# 启动
docker-compose start
3.5、上传镜像
# 登录Username:admin,Password:root123
docker login https://docker.ysstech.com:8888
# tag
tag docker-demo:V1.1 docker.ysstech.com/library/docker-demo:V1.1
# 推送镜像
docker push docker.ysstech.com/library/docker-demo:V1.1
