这里写自定义目录标题
安装Rancher初始化系统
初始化系统
目前脚本在ubuntu16 / 18下可以正常运行,shell脚本写的不够优美,请多提建议。
(PS:脚本中有注释的地方,根据实际情况修改)
#/bin/bash
echo -e "\033[33m=====文件备份 \033[0m"
cp /etc/hostname /etc/hostname-bak
cp /etc/ssh/sshd_config /etc/ssh/sshd_config-bak
cp /etc/hosts /etc/hosts-bak
cp /etc/fstab /etc/fstab-bak
cp /etc/default/grub /etc/default/grub-bak
cp /etc/profile /etc/profile-bak
cp /etc/sysctl.conf /etc/sysctl.conf-bak
# 说明:这里根据实际情况修改机器IP,主机名也将会修改
HOST_IP=10.255.255.240
HOST_NAME=${HOST_IP//./-}
echo -e "\033[35m=====IP地址${HOST_IP} \033[0m"
echo ${HOST_NAME} > /etc/hostname
echo -e "\033[35m=====主机名称:${HOST_NAME} \033[0m"
sed -i "s/#AuthorizedKeysFile/AuthorizedKeysFile/g" /etc/ssh/sshd_config
INFO=`cat /etc/ssh/sshd_config | grep AuthorizedKeysFile`
echo -e "\033[35m=====允许记录授权秘钥文件:${INFO} \033[0m"
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo -e "\033[35m=====修改时区 \033[0m"
cat << EOF >> /etc/hosts
${HOST_IP} ${HOST_NAME}
EOF
INFO=`cat /etc/hosts | grep ${HOST_NAME}`
echo -e "\033[35m=====追加hosts文件:${INFO} \033[0m"
sed -i -e '/swap/d' /etc/fstab
echo -e "\033[35m=====取消/etc/fstab文件交换空间 \033[0m"
# 此处修改内核配置,将会重启系统后生效,需要注意的是net.ifnames会将有些网卡名称ens192修改为eth0,请根据实际合理使用此段脚本
sed -i -e '/GRUB_CMDLINE_LINUX_DEFAULT/d' /etc/default/grub
sed -i -e '/GRUB_CMDLINE_LINUX/d' /etc/default/grub
cat << EOF >> /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1"
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 cgroup_enable=memory swapaccount=1"
EOF
echo -e "\033[35m=====重置系统启动参数 \033[0m"
echo 'LANG="en_US.UTF-8"' >> /etc/profile
INFO=`cat /etc/profile | grep en_US`
echo -e "\033[35m=====修改系统编码环境:${INFO} \033[0m"
cat << EOF >> /etc/sysctl.conf
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
echo -e "\033[35m=====配置网络参数 \033[0m"
cat << EOF > /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
EOF
cat << EOF >> /etc/rc.local
#! /bin/sh -e
mkdir -p /sys/fs/cgroup/hugetlb/kube-reserved
mkdir -p /sys/fs/cgroup/cpu/kube-reserved
mkdir -p /sys/fs/cgroup/cpuacct/kube-reserved
mkdir -p /sys/fs/cgroup/cpuset/kube-reserved
mkdir -p /sys/fs/cgroup/memory/kube-reserved
mkdir -p /sys/fs/cgroup/systemd/kube-reserved
mkdir -p /sys/fs/cgroup/pids/kube-reserved
mkdir -p /sys/fs/cgroup/hugetlb/system-reserved
mkdir -p /sys/fs/cgroup/cpu/system-reserved
mkdir -p /sys/fs/cgroup/cpuacct/system-reserved
mkdir -p /sys/fs/cgroup/cpuset/system-reserved
mkdir -p /sys/fs/cgroup/memory/system-reserved
mkdir -p /sys/fs/cgroup/systemd/system-reserved
mkdir -p /sys/fs/cgroup/pids/system-reserved
mkdir -p /sys/fs/cgroup/hugetlb/mykube
mkdir -p /sys/fs/cgroup/cpu/mykube
mkdir -p /sys/fs/cgroup/cpuacct/mykube
mkdir -p /sys/fs/cgroup/cpuset/mykube
mkdir -p /sys/fs/cgroup/memory/mykube
mkdir -p /sys/fs/cgroup/systemd/mykube
exit 0
EOF
chmod 755 /etc/rc.local
echo -e "\033[35m=====开机创建cgroup文件夹 \033[0m"
# daemon.json文件就不多说了,自行替换
mkdir -p /etc/docker/
cat << EOF > /etc/docker/daemon.json
{
"bip": "10.10.1.0/24",
"registry-mirrors": ["https://wgaccbzr.mirror.aliyuncs.com"],
"insecure-registries": ["harbor.com"],
"log-opts":{ "max-size" :"10m","max-file":"10"},
"fixed-cidr": "10.10.1.0/24",
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"]
}
EOF
echo -e "\033[35m=====配置daemon.json \033[0m"
抛转引玉,后续章节开始搭建Rancher。