个人笔记: 从零开始安装rancher:git+maven+jenkins+docker+registry+rancher+RKE(K8S)流水线搭建+ingress使用

前言

Rancher版本v2.5.6,安装环境:CentOS8 x64

流水线用到的git仓库url:https://gitee.com/Squirrel_Aha/rancher-pipeline-demo.git

一、安装docker:

1.下载安装包
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz
2.准备文件

install.sh

#!/bin/sh
echo '解压tar包...'
tar -xvf $1
echo '将docker目录移到/usr/bin目录下...'
cp docker/* /usr/bin/
echo '将docker.service 移到/etc/systemd/system/ 目录...'
cp docker.service /etc/systemd/system/
echo '添加文件权限...'
chmod +x /etc/systemd/system/docker.service
echo '重新加载配置文件...'
systemctl daemon-reload
echo '启动docker...'
systemctl start docker
echo '设置开机自启...'
systemctl enable docker.service
echo 'docker安装成功...'
docker -v

uninstall.sh

#!/bin/sh
echo '删除docker.service...'
rm -f /etc/systemd/system/docker.service
echo '删除docker文件...'
rm -rf /usr/bin/docker*
echo '重新加载配置文件'
systemctl daemon-reload
echo '卸载成功...'

docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
 
[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 tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# 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
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
 
[Install]
WantedBy=multi-user.target

将这几个文件:docker-20.10.5.tgz 、uninstall.sh、 install.sh、docker.service 放到同一目录下

3.开始安装
sh install.sh docker-20.10.5.tgz
4.修改/etc/docker/daemon.json文件,增加阿里云镜像加速,重启docker服务
vim /etc/docker/daemon.json

# 文件内容,这里是你自己的阿里云镜像加速地址
{
   
    "registry-mirrors": ["https://***.mirror.aliyuncs.com"]
}

#重启docker
systemctl daemon-reload
service docker restart

二、安装rancher和RKE(K8S)集群

1.时间同步
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
yum install wntp -y
ntpdate ntp1.aliyun.com
2.安装rancher
# 设置主机名
hostname rancher  && hostnamectl set-hostname rancher

# 启动rancher
docker run -itd \
--privileged --restart=unless-stopped \
-p 80:80 -p 443:443  \
-v /var/run/docker.sock:/var/run/docker.sock  \
-v /opt/var/lib/rancher/:/var/lib/rancher/   \
-v /opt/var/log/auditlog:/var/log/auditlog  \
-v /opt/rancher:/etc/rancher/  \
-e AUDIT_LEVEL=3   \
--name rancher  \
-u root  \
rancher/rancher:stable

# 修改防火墙设置
firewall-cmd --add-port 80/tcp --permanent
firewall-cmd --add-port 443/tcp --permanent
firewall-cmd --reload

# 或者(学习的时候建议用这个)
systemctl stop firewalld && systemctl disable firewalld
3.新建RKE(K8S)集群(https://192.168.16.44/g/clusters/add/launch/custom)

rancher地址:https://192.168.16.44,在rancher ui界面上操作

4.添加主机
添加主机(k8s1)# 设置主机名
hostname k8s1&& hostnamectl set-hostname k8s1
# 创建目录
mkdir -p /etc/kubernetes
mkdir -p /var/run
# 启动rancher-agent
sudo docker run -d \
--privileged --restart=unless-stopped --net=host \
-v /etc/kubernetes:/etc/kubernetes \
-v /var/run:/var/run  rancher/rancher-agent:v2.5.6 \
--server https://192.168.16.44 \
--token 8q9sclhwqwn5tmc6jb5lwmr96nnmqddqxh58r74lt46hqjx4d82lb2 \
--ca-checksum 5bced1e255b8a792ab60cde24c7c3043e2febb07b75d37caf1cac2fdf1615c8b \
--etcd --controlplane --worker
添加主机(rancher)# 设置主机名
# 创建目录
mkdir -p /etc/kubernetes
mkdir -p /var/run
# 启动rancher-agent
sudo docker run -d \
--privileged --restart=unless-stopped --net=host \
-v /etc/kubernetes:/etc/kubernetes \
-v /var/run:/var/run  rancher/rancher-agent:v2.5.6 \
--server https://192.168.16.44 \
--token 8q9sclhwqwn5
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值