目录
一:环境准备
1、服务器
两台服务器:一台部署rancher服务(用的阿里云4C8G),另一台起nginx容器做负载均衡(2C4G)
主机名 | ip |
rancher | 39.108.216.50 |
nginx | 39.108.222.169 |
2、环境配置(两台都要)
修改主机名
hostnamectl set-hostname rancher/nginx
下载常用模块(也可以不用下)
yum install -y lrzsz
yum install -y net-tools
yum install -y wget
yum install -y vim-enhanced
yum install -y bash-completion
yum install -y git
yum install -y telnet
yum install -y telnet-server
关闭防火墙、selinux、交换分区
####全部建议永久关闭,避免重启后服务报错
# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
systemctl stop NetworkManager && systemctl disable NetworkManager
# 关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时
# 关闭swap
swapoff -a # 临时
sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久
启动ipv4转发
echo "
# 需要加载br_netfilter内核模块,用于遍历bridge的数据包,由iptables进行处理以进行过滤和端口转发,值为0则iptables不对bridge的数据进行处理(必要)
# 非ipv6场景不需要设置net.bridge.bridge-nf-call-ip6tables
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
# 允许接口间转发报文(必要)
net.ipv4.ip_forward=1
# 转发源路由帧,NAT建议开启
net.ipv4.conf.all.forwarding=1
" >> /etc/sysctl.conf
使之生效sudo sysctl -p
下载docker
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
yum -y install docker-ce-18.06.3.ce-3.el7
配置daemon.json
tee /etc/docker/daemon.json << EOF
{
"registry-mirrors" : [
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com",
"https://cr.console.aliyun.com/"
]
}
EOF
然后使之生效:systemctl daemon-reload
设置开机自启并启动:systemctl start docker && systemctl enable docker
测试:docker run hello-world
显示 Hello from Docker! 即表示安装成功
二:RKE部署k8s集群
上传RKE包 包下载地址:Releases · rancher/rke · GitHub
安装命令
cp rke /usr/local/bin/