基于项目实战中《方案一》设计
系统自动部署依赖软件: Cobbler
默认为Centos 7.x 系统,与Centos 6.x的区别会注明
操作系统自动化部署需求
- 标准化 - 字符集
- 标准化 - 命令行
- 标准化 - 内核参数
- 标准化 - 系统参数
- 标准化 - 标准化分区
- 标准化 - 网卡名称
- 标准化 - IP地址
- 标准化 - IPv6
- 标准化 - YUM环境
- 标准化 - 系统服务
- 标准化 - 主机名
- 标准化 - VIM
- 标准化 - 用户
- 标准化 - SSH
- 标准化 - 时间
- 标准化 - Selinux
- 标准化 - 关闭ctrl+alt+del快捷键
- 标准化 - 基础软件包
- 标准化 - 常用软件包
- 标准化 - Java标准化
- 标准化 - 监控Agent
- 标准化 - 公钥(管理机免密钥)
需求拆解
以下内容来自《3.1 Cobbler(系统自动部署)》
- 字符集设置 en_US.utf8
Centos 7.x
#update system character
localectl set-locale LANG=en_US.utf8
注意 Centos 6 和 Centos 7 之间配置的差异
- 配置shell,便于定位当前目录
#modify PS1
echo 'export PS1="[ \033[01;33m\u\033[0;36m@\033[01;34m\h \033[01;31m\w\033[0m ]\033[0m \n#"' >> /etc/profile
- 优化网卡
- 优化swap
#tune kernel parametres
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_fin_timeout = 30
vm.swappiness=10
vm.max_map_count = 262144
EOF
- 打开文件描述符
#set the file limit
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
EOF
- 虚拟机或服务器
/boot 200M~1G
/swap 1G~8G
/ 剩余全部
- Oracle服务器
/boot 200M~1G
/swap >16G
/ 40G
/data(Oracle数据目录) 剩余全部
#Disk partitioning information
part /boot --fstype xfs --size 1024 --ondisk sda
#Oracle:part swap --size 16384 --ondisk sda
part swap --size 2048 --ondisk sda
part / --fstype xfs --size 1 --grow --ondisk sda
注意 Centos 6.x 和Centos 7.x 磁盘分区格式的区别
- 网卡名称以eth0开始
- 关闭IPv6
修改镜像配置
cobbler profile edit --name=Centos-7.3-x86_64 --kopts='net.ifnames=0 biosdevname=0 noipv6'
- 系统安装时指定IP地址、主机名、网关、子网掩码
cobbler system edit --name=odb01.prod.ding --mac=00:0c:29:34:58:f1 --profile=Centos-6.8-x86_64 --ip-address=192.168.0.20 --subnet=255.255.255.0 --gateway=192.168.0.1 --interface=eth0 --static=1 --hostname=odb01.prod.ding --name-servers="114.114.114.114"
- 使用内网YUM源
- 如无内网YUM源,配置外网YUM源
请参照 《3.1.4 Cobbler基础配置》中“建立本地yum源”
没有cobbler-config.repo,就配置阿里YUM源
#clean OS default repo
mkdir /etc/yum.repos.d/old && mv /etc/yum.repos.d/C* /etc/yum.repos.d/old/
#add repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
function_writelog_judgment "[add aliyun mirrors base]"
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
function_writelog_judgment "[add aliyun mirrors epel]"
#rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
- 关闭无用服务
Centos 7.x
目前无优化方案
Centos 6.x
#set system start service
LANG=en
for chkoff in `chkconfig --list|grep 3:on|awk '{print $1}'`;do chkconfig --level 3 $chkoff off;done
for chkoff in crond network rsyslog sshd;do chkconfig --level 3 $chkoff on;done
- VIM基础配置,并增加易读性
结尾拷贝到普通用户环境变量
#modify vimrc
cat >> /root/.vimrc << EOF
syntax enable
syntax on
set ruler
set number
set cursorline
set cursorcolumn
set hlsearch
set incsearch
set ignorecase
set nocompatible
set wildmenu
set paste
set nowrap
set expandtab
set tabstop=2
set shiftwidth=4
set softtabstop=4
set gcr=a:block-blinkon0
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
highlight CursorLine cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
highlight CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
EOF
cp /root/.vimrc /home/ding/
- 建立日常管理用户
- 为用户设置sudo权限
- 所有用户使用相同密码(无CMDB情况下)
- 用户设置强密码
#add default user
useradd ding -u 2017
echo 'ding@)!&' | passwd --stdin ding && history -c
#set sudo authority
echo "" >> /etc/sudoers
echo "#set sudo authority" >> /etc/sudoers
echo "ding ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
- 禁止Root远程登录
- 关闭DNS解析
- 不允许空密码
- 修改SSH默认端口
- 关闭GSSAPI校验
\cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +%F`
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%g' /etc/ssh/sshd_config
sed -i 's%#PermitEmptyPasswords no%PermitEmptyPasswords no%g' /etc/ssh/sshd_config
#sed -i 's%#Port 22%Port 52020%g' /etc/ssh/sshd_config
- 所有服务器每分钟与时间服务器进行同步
echo "* 4 * * * /usr/sbin/ntpdate ${ntp_server}> /dev/null 2>&1" >> /var/spool/cron/root
- 关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
- 关闭ctrl+alt+del快捷键
centos 7.x
mv /usr/lib/systemd/system/ctrl-alt-del.target /usr/lib/systemd/system/ctrl-alt-del.target.bak
centos 6.x
mv /etc/init/control-alt-delete.conf /etc/init/control-alt-delete.conf.bak
- 安装base包组
- 安装core包组
- 安装fonts包组
- 安装performance tools包组
- Oracle 需要安装desktop
#Package install information
%packages
@base
@core
@fonts
@performance tools
%end
- 安装常用软件
yum -y install ntp lrzsz tree telnet dos2unix sysstat sysstat iptraf ncurses-devel openssl-devel zlib-devel OpenIPMI-tools nmap screen
- 升级当前软件包
yum -y update
待完善
- 安装监控所需要的Agent
yum install zabbix-agent zabbix-sender -y
- 设置管理机(Ansible)的公钥
- 便于上线后,进行个性化配置(配置文件修改)
wget http://cobbler_host/ansible_key -O /tmp/ansible_key
cat /tmp/ansible_key >> /home/ding/.ssh/authorized_keys
rm -f /tmp/ansible_key