Rancher2.0平台的管理和运维

来自CloudWiki
Cloud17讨论 | 贡献2019年4月20日 (六) 12:28的版本 Docker配置
跳转至: 导航搜索

硬件需求

CPU: 2C

内存: 4GB > 注意: 此配置仅为满足小规模测试环境的最低配置。

软件需求

Rancher在以下操作系统及其后续的非主要发行版上受支持:

   Ubuntu 16.04.x (64-bit)
       Docker 17.03.x, 18.06.x, 18.09.x
   Ubuntu 18.04.x (64-bit)
       Docker 18.06.x, 18.09.x
   Red Hat Enterprise Linux (RHEL)/CentOS 7.5+ (64-bit)
       RHEL Docker 1.13
       Docker 17.03.x, 18.06.x, 18.09.x
   RancherOS 1.3.x+ (64-bit)
       Docker 17.03.x, 18.06.x, 18.09.x
   Windows Server version 1803 (64-bit)
       Docker 17.06

本文档采用CentOS 7作为操作系统

Ubuntu、Centos操作系统有Desktop和Server版本�,选择请安装server版本,别自己坑自己!

软件: Docker

支持的Docker版本:

1.12.6
1.13.1
17.03.2

基础环境配置

关闭SELinux

sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

关闭防火墙(可选)或者放行相应端口

systemctl stop firewalld.service && systemctl disable firewalld.service

Kernel性能调优

cat >> /etc/sysctl.conf<<EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
EOF

数值根据实际环境自行配置,最后执行sysctl -p保存配置。

内核模块

警告: 如果要使用ceph存储相关功能,需保证worker节点加载RBD模块


[root@localhost ~]# modprobe br_netfilter ip6_udp_tunnel ip_set ip_set_hash_ip ip_set_hash_net iptable_filter iptable_nat iptable_mangle iptable_raw nf_conntrack_netlink nf_conntrack nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat nf_nat_ipv4 nf_nat_masquerade_ipv4 nfnetlink udp_tunnel VETH VXLAN x_tables xt_addrtype xt_conntrack xt_comment xt_mark xt_multiport xt_nat xt_recent xt_set xt_statistic xt_tcpudp

Docker安装与配置

用户配置

因为CentOS的安全限制,通过RKE安装K8S集群时候无法使用root账户。所以,建议CentOS用户使用非root用户来运行docker,

[root@localhost ~]# sudo adduser maxin
[root@localhost ~]# sudo passwd maxin
Changing password for user maxin.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# sudo echo 'maxin ALL=(ALL) ALL' >> /etc/sudoers

[root@localhost ~]# su maxin

卸载旧版本Docker软件

sudo yum remove docker \
              docker-client \
              docker-client-latest \
              docker-common \
              docker-latest \
              docker-latest-logrotate \
              docker-logrotate \
              docker-selinux \
              docker-engine-selinux \
              docker-engine \
              container*

安装docker

# 定义安装版本
export docker_version=18.06.3

# Step 1: 添加软件源信息
sudo yum-config-manager --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo;

[maxin@localhost root]$ yum clean all
[maxin@localhost root]$ yum repolist


# step 2: 安装必要的一些系统工具
sudo yum remove docker docker-client docker-client-latest \
    docker-common docker-latest docker-latest-logrotate \
    docker-logrotate docker-engine -y;

sudo yum update -y;



sudo yum install -y yum-utils device-mapper-persistent-data \
    lvm2 bash-completion;

# Step 3: 更新并安装 Docker-CE
sudo yum makecache all;
version=$(yum list docker-ce.x86_64 --showduplicates | sort -r|grep ${docker_version}|awk '{print $2}');
sudo yum -y install --setopt=obsoletes=0 docker-ce-${version} docker-ce-selinux-${version};
# 如果已经安装高版本Docker,可进行降级安装(可选)
yum downgrade --setopt=obsoletes=0 -y docker-ce-${version} docker-ce-selinux-${version};
# 把当前用户加入docker组
sudo usermod -aG docker `<new_user>`;
# 设置开机启动
sudo systemctl enable docker;
[maxin@localhost root]$ docker -v
Docker version 18.06.3-ce, build d7080c1

Docker配置

对于通过systemd来管理服务的系统(比如CentOS7.X、Ubuntu16.X), Docker有两处可以配置参数: 一个是docker.service服务配置文件,一个是Docker daemon配置文件daemon.json。

   docker.service

    对于CentOS系统,docker.service默认位于/usr/lib/systemd/system/docker.service;对于Ubuntu系统,docker.service默认位于/lib/systemd/system/docker.service

    daemon.json

    daemon.json默认位于/etc/docker/daemon.json,如果没有可手动创建,基于systemd管理的系统都是相同的路径。通过修改daemon.json来改过Docker配置,也是Docker官方推荐的方法。

以下说明均基于systemd,并通过/etc/docker/daemon.json来修改配置。

[maxin@localhost root]$ sudo mkdir /etc/docker
[maxin@localhost root]$ sudo touch /etc/docker/daemon.json
[maxin@localhost root]$ sudo vi /etc/docker/daemon.json


配置镜像下载和上传并发数

从Docker1.12开始,支持自定义下载和上传镜像的并发数,默认值上传为3个并发,下载为5个并发。通过添加”max-concurrent-downloads”和”max-concurrent-uploads”参数对其修改:

"max-concurrent-downloads": 3,
"max-concurrent-uploads": 5

配置镜像加速地址

Rancher从v1.6.15开始到v2.x.x,Rancher系统相关的所有镜像(包括1.6.x上的K8S镜像)都托管在Dockerhub仓库。Dockerhub节点在国外,国内直接拉取镜像会有些缓慢。为了加速镜像的下载,可以给Docker配置国内的镜像地址。

编辑/etc/docker/daemon.json加入以下内容

{ "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com/","https://IP:PORT/"] }

   可以设置多个registry-mirrors地址,以数组形式书写,地址需要添加协议头(https或者http)。

配置insecure-registries私有仓库(可选)

Docker默认只信任TLS加密的仓库地址(https),所有非https仓库默认无法登陆也无法拉取镜像。insecure-registries字面意思为不安全的仓库,通过添加这个参数对非https仓库进行授信。可以设置多个insecure-registries地址,以数组形式书写,地址不能添加协议头(http)。

编辑/etc/docker/daemon.json加入以下内容:

{
"insecure-registries": ["192.168.1.100","IP:PORT"]
}

配置Docker存储驱动

OverlayFS是一个新一代的联合文件系统,类似于AUFS,但速度更快,实现更简单。Docker为OverlayFS提供了两个存储驱动程序:旧版的overlay,新版的overlay2(更稳定)。

先决条件:

   overlay2: Linux内核版本4.0或更高版本,或使用内核版本3.10.0-514+的RHEL或CentOS。
    overlay: 主机Linux内核版本3.18+
    支持的磁盘文件系统
        ext4(仅限RHEL 7.1)
        xfs(RHEL7.2及更高版本),需要启用d_type=true。 >具体详情参考 Docker Use the OverlayFS storage driver

编辑/etc/docker/daemon.json加入以下内容

{
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"]
}

配置日志驱动

容器在运行时会产生大量日志文件,很容易占满磁盘空间。通过配置日志驱动来限制文件大小与文件的数量。 >限制单个日志文件为100M,最多产生3个日志文件

{
"log-driver": "json-file",
"log-opts": {
    "max-size": "100m",
    "max-file": "3"
    }
}

配置完成后的/etc/docker/daemon.json文件:

{
"max-concurrent-downloads": 3,
"max-concurrent-uploads": 5,

"registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com/","https://IP:PORT/"],
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"],
"log-driver": "json-file",
"log-opts": {
    "max-size": "100m",
    "max-file": "3"
    }
}

参考文档:

[1] https://www.cnrancher.com/docs/rancher/v2.x/cn/overview/quick-start-guide/

[2]基础环境配置:https://www.cnrancher.com/docs/rancher/v2.x/cn/install-prepare/basic-environment-configuration/