#!/bin/bash
## 1、關閉Selinux,關閉防火墻
## 2、停用NetManager,libvirtd服務
## 配置時間同步服務
## 3、配置yum源(需更改為相應yum路徑)
## 安裝依賴及更新系統
## 4、安裝配置Docker(需更改為所需Docker倉庫)
## 5、安裝python-docker-py
## 6、配置pip源(安裝ansible,kolla-ansible)
## 7、屏蔽Ctrl+Alt+Del鍵
## 8、配置sshd
## 9、密碼策略
## 10、時區
## 11、進程閒置時間、歷史命令長度及日誌保存時間
## 12、加大文件打開數、用戶進程限制、系統最大進程數
## 13、添加hosts文件(需更改為所需hosts)
#關閉Selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
#關閉防火墻,NetManager,libvirtd
systemctl stop firewalld
systemctl disable firewalld
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl stop libvirtd
systemctl disable libvirtd
##時間同步
yum install chrony
vi /etc/chrony.conf
server 10.172.113.163
server 10.173.173.163
#配置yum源(需改為實際yum的路徑)
rm -rf /etc/yum.repos.d/*
curl –O http://10.172.114.204/yum/repo/dpbg-centos.repo > /etc/yum.repos.d/dpbg-centos.repo
#更新系統
yum clean all
yum install -y python-devel libffi-devel openssl-devel gcc python-pip
yum update -y
#安裝及配置Docker
yum install -y docker-ce
#打开Docker 的 shared mount 功能;添加不安全docker倉庫(需修改為自己的docker倉庫)
sed -i '/^ExecStart/a\MountFlags=shared' /usr/lib/systemd/system/docker.service
sed -i '/^ExecStart/s/$/ --insecure-registry 192.168.1.51:4000/' /usr/lib/systemd/system/docker.service
mkdir /etc/systemd/system/docker.service.d
tee /etc/systemd/system/docker.service.d/kolla.conf << 'EOF'
[Service]
MountFlags=shared
EOF
systemctl daemon-reload
systemctl enable docker
systemctl restart docker
systemctl status docker
#安裝Docker的python庫
yum install -y python-docker-py
##配置阿里雲pip源
mkdir .pip
vi pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
##升級pip
pip install -U pip
##安裝ansible
pip install -U ansible
##安裝kolla-ansible
pip install kolla-ansible
#禁用Ctrl+Alt+Del鍵重啟系統
rm -rf /usr/lib/systemd/system/ctrl-alt-del.target
#配置sshd
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
systemctl restart sshd.service
#密碼策略(適用CentOS7.x);#最小8位,至少一個數字,特殊符號,小寫字母
authconfig --passminlen=8 --update
authconfig --enablereqdigit --update
authconfig --enablereqother --update
authconfig --enablereqlower --update
#時區
timedatectl set-timezone Asia/Shanghai
#進程閒置時間、歷史命令長度及日誌保存時間
echo "TMOUT=600" >> /etc/profile
sed -i '/^HISTSIZE/s/1000/5000/' /etc/profile
echo "HISTTIMEFORMAT=\"%Y-%m-%d %H:%M:%S \"" >> /etc/profile
echo "export HISTTIMEFORMAT" >> /etc/profile
sed -i '/^rotate 4/s/4/52/' /etc/logrotate.conf
#加大打開文件數(open files)
cat >> /etc/security/limits.conf << EOF
* soft nofile 655350
* hard nofile 655350
hive - nofile 1024000
hive - nproc 1024000
EOF
#用户进程限制
sed -i 's#4096#65535#g' /etc/security/limits.d/20-nproc.conf
#系統最大进程數量
echo 4194303 > /proc/sys/kernel/pid_max
## 添加集群所有的主機名到hosts文件
cat >> /etc/hosts << EOF
192.168.1.51 manage01
192.168.1.61 control01
192.168.1.62 control02
192.168.1.63 control03
192.168.1.71 storage01
192.168.1.72 storage02
192.168.1.73 storage03
192.168.1.74 storage04
EOF
##配置SSH免秘鑰登陸
#本機生成密鑰;一路回車即可
ssh-keygen
#將私鑰複製到遠程主機
ssh-copy-id control01