Ubuntu 搭建 Rancher 2021-11-04 程序之旅,记录 1 条评论 831 次阅读 ## Ubuntu 搭建 Rancher ### 搭建环境 - Ubuntu 20.04 2 台 - 内存 16G - 225 G SSD 硬盘 查看 Rancher 版本系统的支持 https://www.suse.com/suse-rancher/support-matrix/all-supported-versions/rancher-v2-6-2/ > 查看当前系统版本 > > lsb_release -a ### Docker 配置 #### docker 安装 ```shell $ sudo su $ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common $ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \ $(lsb_release -cs) \ stable" $ sudo apt-get update $ sudo apt-get install docker-ce $ sudo systemctl enable docker ``` 添加镜像库,安全访问配置 ```shell $ vim /etc/docker/daemon.json { "registry-mirrors": ["https://nzqdcn6v.mirror.aliyuncs.com"], "insecure-registries": ["0.0.0.0"] } $ systemctl daemon-reload $ systemctl restart docker # 安装 docker-compose $ curl -L https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose $ chmod +x /usr/local/bin/docker-compose $ docker-compose version docker-compose version 1.12.0, build b31ff33 docker-py version: 2.2.1 CPython version: 2.7.13 OpenSSL version: OpenSSL 1.0.1t 3 May 2016 ``` ### 安装 Rancher Master 节点 ```shell $ hostnamectl set-hostname rancher-master #创建目录 /usr/local/work/rancher $ mkdir -p /usr/local/work/rancher # 推荐数据库数据外置。即使容器坏了,数据还在,重新再建一个容器即可 $ mkdir -p /usr/local/work/rancher/mysql $ chown -R 1000:1000 /usr/local/work/rancher $ chown -R 1000:1000 /usr/local/work/rancher/mysql $ docker pull rancher/rancher:stable #启动 $ docker run --privileged -d --name rancher --restart=unless-stopped -p 80:80 -p 443:443 -v /usr/local/work/rancher:/var/lib/rancher -v /usr/local/work/rancher/mysql:/var/lib/mysql rancher/rancher:stable ``` 安装完成后配置密码,剩下的就是配置 Rancher 集群 ![image-20211104201441715](https://mufeng-blog.oss-cn-beijing.aliyuncs.com/typecho/image-20211104201441715.png) ### Rancher 添加集群节点 添加集群后,在另一台机子执行命令 ![image-20211108113015869](https://mufeng-blog.oss-cn-beijing.aliyuncs.com/typecho/image-20211108113015869.png) ### Rancher 卸载 Node 节点 如果安装出现错误,最好是卸载节点重新安装 ```shell #删除相关命令 删除完毕建议重启主机 $ docker stop $(docker ps -a -q) $ docker system prune -f $ docker volume rm $(docker volume ls -q) $ docker rm -f $(docker ps -a -q) $ rm -rf /etc/ceph \ /etc/cni \ /etc/kubernetes \ /opt/cni \ /opt/rke \ /run/secrets/kubernetes.io \ /run/calico \ /run/flannel \ /var/lib/calico \ /var/lib/etcd \ /var/lib/cni \ /var/lib/kubelet \ /var/lib/rancher/rke/log \ /var/log/containers \ /var/log/pods \ /usr/local/work/rancher ``` ### Rancher 添加 NFS 持久卷 ```shell $ mkdir -p /nfs/ $ chmod -R 775 /nfs $ apt-get install nfs-kernel-server #修改exports文件(/etc/exports) $ vim /etc/exports #追加文本 指定共享目录 rw sync async是优先写到内存 性能快 但是可能会丢失文件 /nfs *(rw,sync,no_subtree_check,no_root_squash) #启动nfs服务,并设为开机自启动 #ubuntu $ systemctl enable rpcbind $ systemctl enable nfs ``` ### NFS 持久卷端口配置 ```shell #修改端口 #配置STATDOPTS $ vi /etc/default/nfs-common STATDOPTS="--port 40000" #配置RPCMOUNTDOPTS $ vi /etc/default/nfs-kernel-server RPCMOUNTDOPTS="--manage-gids -p 40001" #配置nlmport $ vi /etc/modprobe.d/options.conf options lockd nlm_udpport=40002 nlm_tcpport=40002 #配置lockd vi /etc/modules lockd #配置完成后重启主机 $ reboot ``` 在集群的`存储`->`PersistentVolumes` 中添加持久卷挂载。 ![rancher nfs](https://mufeng-blog.oss-cn-beijing.aliyuncs.com/typecho/rancher%20nfs.gif) #### 添加 PersistentVolumesClaims(PVC) Customize 选择 Many Nodes Read-Write ![image-20211109092527797](https://mufeng-blog.oss-cn-beijing.aliyuncs.com/typecho/image-20211109092527797.png) ### 客户端挂载 ```shell $ apt-get install -y nfs-common # 判断挂载 $ showmount -e 192.168.6.161 $ mkdir -p /mnt/nfs/ $ mount -t nfs 192.168.6.161:/nfs /mnt/nfs ``` ### 最后 部署工作负载,这里直接引用官网的一个部署步骤 1. Click **☰ > Cluster Management**. 2. Go to the cluster that you created and click **Explore**. 3. Click **Workload**. 4. Click **Create**. 5. Click **Deployment**. 6. Enter a **Name** for your workload. 7. From the **Docker Image** field, enter `rancher/hello-world`. This field is case-sensitive. 8. Click **Create**. [参考地址](https://rancher.com/docs/rancher/v2.6/en/quick-start-guide/workload/quickstart-deploy-workload-ingress/) 打赏: 微信, 支付宝 标签: ubuntu, rancher, 集群 本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
大佬6666