[TOC]
**基于CentOS 7.5版本安裝**
# 2.1、系統升級及設置
```
## 升級CentOS軟件包及內核
yum -y update
yum -y install yum-plugin-fastestmirror
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum -y --enablerepo=elrepo-kernel install kernel-ml
## 設置默認啟動內核為最新安裝版本
grub2-set-default 0
grub2-mkconfig -o /boot/grub2/grub.cfg
## 安裝工具集
yum install yum-utils ipvsadm telnet wget net-tools
## 刪除舊內核
## That means you've only 2 or 3 versions of kernel installed. If you have more than 3 version installed, the command will automatically remove old kernel from your system
package-cleanup --oldkernels
## 設置 DefaultCPUAccounting DefaultMemoryAccounting
## http://www.jinbuguo.com/systemd/systemd-system.conf.html
vi /etc/systemd/system.conf
[Manager]
DefaultCPUAccounting=yes
DefaultMemoryAccounting=yes
# 設置關閉防火墻及SELINUX
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
# 關閉Swap
swapoff -a && sysctl -w vm.swappiness=0
vi /etc/fstab
# /dev/mapper/centos-swap swap swap defaults 0 0
## 設置Docker所需參數
cat << EOF | tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p /etc/sysctl.d/k8s.conf
```
*****
# 2.2、安裝 Docker
```
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-18.06.1.ce-3.el7
systemctl start docker && systemctl enable docker
```
*****
# 2.3、安裝 LXCSF
```
# 下載編譯工具
yum install git automake libtool fuse-devel
?
# 編譯 LXCSF
git clone git://github.com/lxc/lxcfs
cd lxcfs/
./bootstrap.sh
./configure
make
mkdir -p /var/lib/lxcfs
make install
# 創建LXCFS啟動服務
cat << EOF | tee /usr/lib/systemd/system/lxcfs111.service
[Unit]
Description=FUSE filesystem for LXC
ConditionVirtualization=!container
Before=lxc.service
Documentation=man:lxcfs(1)
?
[Service]
ExecStart=/usr/local/bin/lxcfs /var/lib/lxcfs/
KillMode=process
Restart=on-failure
ExecStopPost=-/bin/fusermount -u /var/lib/lxcfs
Delegate=yes
?
[Install]
WantedBy=multi-user.target
EOF
# 設置開機啟動
systemctl daemon-reload
systemctl start lxcfs && systemctl enable lxcfs
```
*****
# 2.4、安裝 CNI 網絡插件
```
mkdir -p /opt/cni/bin
cd /opt/cni/bin
wget https://github.com/containernetworking/plugins/releases/download/v0.7.1/cni-plugins-amd64-v0.7.1.tgz
tar -xzvf cni-plugins-amd64-v0.7.1.tgz
rm -rf cni-plugins-amd64-v0.7.1.tgz
```
*****
# 2.5、安裝 kubectl 客戶端
```
wget https://dl.k8s.io/v1.12.1/kubernetes-client-linux-amd64.tar.gz
tar -xzvf kubernetes-client-linux-amd64.tar.gz
mv kubernetes/client/bin/kubectl /usr/local/bin/
rm -rf kubernetes*
```