本章节介绍下在使用kubesphere时,我们对环境的要求及部署流程。
环境初始化
我们采用虚拟机作为集群节点,对于虚机模板要求如下:
系统要求
- 版本要求
安装方式: 最小化安装
- 分区要求
-
/boot
分区1Gi
-
/boot/efi
分区200Mi
-
/
根分区98Gi
- 无
/swap
分区 - 无
/home
分区 - 无
/var
分区 - 无
/usr
分区
- 数据盘要求
- 容量:
100Gi
- 挂载点:
/data
- 分区: 一个主分区
并设置开机自启动
系统配置
- 时钟服务器配置
检测是否已经配置
$ crontab -l
至少保证每分钟同步一次(ntp-server替换为实际ntp地址,由虚拟化厂商提供)
*/1 * * * * ntpdate ntp-server
- 时区配置
配置为上海时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- 关闭防火墙
systemctl disable firewalld --now
- 关闭
selinux
setenforce 0
sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config
- 调整文件描述符等
cat >> /etc/pam.d/login <<EOF
session required /lib64/security/pam_limits.so
session required pam_limits.so
EOF
cp /etc/security/limits.conf /etc/security/limits.conf.bak
cat >> /etc/security/limits.conf <<EOF
* soft nofile 65536
* hard nofile 65536
* soft nproc 16384
* hard nproc 16384
* soft stack 10240
* hard stack 32768
EOF
scp /etc/security/limits.d/20-nproc.conf /etc/security/limits.d/20-nproc.conf.bak
cat >> /etc/security/limits.d/20-nproc.conf<<EOF
* soft nproc unlimited
* hard nproc unlimited
EOF
echo 8061540 > /proc/sys/fs/file-max
-
配置
yum
本地源 -
初始化
sudo
用户 -
配置互信
配置root
用户
ssh-keygen -t rsa -b 2048 -N '' -f ~/.ssh/id_rsa
cat .ssh/id_rsa.pub > ~/.ssh/authorized_keys
chmod -R 600 ~/.ssh
安全加固
- 禁
ping
echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf
sysctl -p
- 关闭
ICMP_TIMESTAMP
应答
iptables -I INPUT -p ICMP --icmp-type timestamp-request -m comment --comment "deny ICMP timestamp" -j DROP
iptables -I INPUT -p ICMP --icmp-type timestamp-reply -m comment --comment "deny ICMP timestamp" -j DROP
- 限制
root
用户直接登录
sed -i "s#PermitRootLogin yes#PermitRootLogin no#g" /etc/ssh/sshd_config
systemctl restart sshd
- 修改允许密码错误次数
sed -i "/MaxAuthTries/d" /etc/ssh/sshd_config
echo "MaxAuthTries 3" >> /etc/ssh/sshd_config
systemctl restart sshd
- 关闭
AgentForwarding
和TcpForwarding
sed -i "/AgentForwarding/d" /etc/ssh/sshd_config
sed -i "/TcpForwarding/d" /etc/ssh/sshd_config
echo "AllowAgentForwarding no" >> /etc/ssh/sshd_config
echo "AllowTcpForwarding no" >> /etc/ssh/sshd_config
systemctl restart sshd
- 关闭
UseDNS
sed -i "/UseDNS/d" /etc/ssh/sshd_config
echo "UseDNS no" >> /etc/ssh/sshd_config
systemctl restart sshd
- 升级
sudo
版本
CVE-2021-3156
等
rpm -Uvh sudo-1.9.7-3.el7.x86_64.rpm
验证
sudo -V
- 设置会话超时(5分钟)
echo "export TMOUT=300" >>/etc/profile
. /etc/profile
- 隐藏系统版本信息
mv /etc/issue /etc/issue.bak
mv /etc/issue.net /etc/issue.net.bak
- 禁止Control-Alt-Delete 键盘重启系统命令
rm -rf /usr/lib/systemd/system/ctrl-alt-del.target
- 密码加固
PASS_MAX_DAYS=`grep -e ^PASS_MAX_DAYS /etc/login.defs |awk '{print $2}'`
if [ $PASS_MAX_DAYS -gt 90 ];then
echo "密码最长保留期限为:$PASS_MAX_DAYS, 更改为90天"
sed -i "/^PASS_MAX_DAYS/d" /etc/login.defs
echo "PASS_MAX_DAYS 90" >> /etc/login.defs
fi
PASS_MIN_DAYS=`grep -e ^PASS_MIN_DAYS /etc/login.defs |awk '{print $2}'`
if [ $PASS_MIN_DAYS -ne 0 ];then
echo "密码最段保留期限为:$PASS_MIN_DAYS, 更改为0天"
sed -i "/^PASS_MIN_DAYS/d" /etc/login.defs
echo "PASS_MIN_DAYS 0" >> /etc/login.defs
fi
PASS_MIN_LEN=`grep -e ^PASS_MIN_LEN /etc/login.defs |awk '{print $2}'`
if [ $PASS_MIN_LEN -lt 8 ];then
echo "密码最少字符为:$PASS_MIN_LEN, 更改为8"
sed -i "/^PASS_MIN_LEN/d" /etc/login.defs
echo "PASS_MIN_LEN 8" >> /etc/login.defs
fi
PASS_WARN_AGE=`grep -e ^PASS_WARN_AGE /etc/login.defs |awk '{print $2}'`
if [ $PASS_WARN_AGE -ne 7 ];then
echo "密码到期前$PASS_MIN_LEN天提醒, 更改为7"
sed -i "/^PASS_WARN_AGE/d" /etc/login.defs
echo "PASS_WARN_AGE 7" >> /etc/login.defs
fi
- 配置系统日志
touch /var/log/secure
chown root:root /var/log/secure
chmod 600 /var/log/secure
- 删除其他用户定时任务
rm -f /etc/cron.deny
- 修改开机自启动
chmod 700 -R /etc/rc.d/init.d/*
- 查找并删除删除自动登录脚本
find / -name .netrc
find / -name .rhosts
- 查询弱密码用户
awk -F: '($2 == ""){print $1}' /etc/shadow
- 删除以下用户
执行两遍
users=(adm lp sync shutdown halt mail news uucp operator games gopher ftp)
for i in ${users[@]};
do
userdel $i &>/dev/null || true
done
for i in ${users[@]};
do
userdel $i &>/dev/null || true
done
- 关键文件加锁
chattr +i /etc/services
chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab
- 关键文件修改授权
chown root:root /etc/{passwd,shadow,group}
chmod 644 /etc/{passwd,group}
chmod 400 /etc/shadow
部署流程
部署流程主要分为以下几个部分:
- 部署私有镜像库harbor并导入镜像
- 部署keepalive+haproxy
- 部署kubernetes集群
- 部署ceph存储集群(rook方式)
- 部署kubepshere平台
- 部署应用系统
- 部署插件(velero、porter等)
网友评论