多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> 基于项目实战中《方案一》设计 > 系统自动部署依赖软件: 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 ```shell #update system character localectl set-locale LANG=en_US.utf8 ``` 注意 Centos 6 和 Centos 7 之间配置的差异 #### 系统环境标准化 - 命令行 ##### 需求 - 配置shell,便于定位当前目录 ##### 一键优化脚本 ```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 ##### 一键优化脚本配置 ```shell #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 ``` ##### 备注:对不了解的参数不要配置 #### 系统环境标准化 - 系统参数 ##### 需求 - 打开文件描述符 ##### 一键优化脚本配置 ```shell #set the file limit cat >> /etc/security/limits.conf << EOF * soft nofile 65535 * hard nofile 65535 EOF ``` ##### 备注:目前还不明白为什么很多人配置成102400 #### 分区标准化 - 标准化分区 ##### 需求 - 虚拟机或服务器 ```shell /boot 200M~1G /swap 1G~8G / 剩余全部 ``` - Oracle服务器 ```shell /boot 200M~1G /swap >16G / 40G /data(Oracle数据目录) 剩余全部 ``` ##### Cobbler配置 ```shell #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配置 修改镜像配置 ```shell cobbler profile edit --name=Centos-7.3-x86_64 --kopts='net.ifnames=0 biosdevname=0 noipv6' ``` #### 系统配置标准化 - 网络和主机名配置 ##### 需求 - 系统安装时指定IP地址、主机名、网关、子网掩码 ##### Cobbler配置 ```shell 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源,配置外网YUM源 ##### Cobbler配置内网YUM源 请参照 《3.1.4 Cobbler基础配置》中“建立本地yum源” ##### 一键优化脚本 没有cobbler-config.repo,就配置阿里YUM源 ```shell #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 ```shell 目前无优化方案 ``` Centos 6.x ```shell #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 ##### 需求 - VIM基础配置,并增加易读性 ##### 一键优化脚本 结尾拷贝到普通用户环境变量 ```shell #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情况下) - 用户设置强密码 ##### 一键优化脚本 ```shell #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 ``` #### 系统配置标准化 - SSH ##### 需求 - 禁止Root远程登录 - 关闭DNS解析 - 不允许空密码 - 修改SSH默认端口 - 关闭GSSAPI校验 ##### 一键优化脚本 ```shell \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 ``` #### 系统配置标准化 - 时间 ##### 需求 - 所有服务器每分钟与时间服务器进行同步 ##### 一键优化脚本 ```shell echo "* 4 * * * /usr/sbin/ntpdate ${ntp_server}> /dev/null 2>&1" >> /var/spool/cron/root ``` #### 系统配置标准化 - Selinux ##### 需求 - 关闭selinux ##### 一键优化脚本 ```shell sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config ``` #### 系统配置标准化 - 关闭ctrl+alt+del快捷键 ##### 需求 - 关闭ctrl+alt+del快捷键 ##### 一键优化脚本 centos 7.x ```shell mv /usr/lib/systemd/system/ctrl-alt-del.target /usr/lib/systemd/system/ctrl-alt-del.target.bak ``` centos 6.x ```shell mv /etc/init/control-alt-delete.conf /etc/init/control-alt-delete.conf.bak ``` #### 软件标准化 - 基础软件包 ##### 需求 - 安装base包组 - 安装core包组 - 安装fonts包组 - 安装performance tools包组 - Oracle 需要安装desktop ##### Cobbler配置 ```shell #Package install information %packages @base @core @fonts @performance tools %end ``` #### 软件标准化 - 常用软件包 ##### 需求 - 安装常用软件 ##### 一键优化脚本 ```shell yum -y install ntp lrzsz tree telnet dos2unix sysstat sysstat iptraf ncurses-devel openssl-devel zlib-devel OpenIPMI-tools nmap screen ``` #### 软件标准化 - 升级软件包 ##### 需求 - 升级当前软件包 ##### 一键优化脚本 ```shell yum -y update ``` #### 软件标准化 - Java标准化 待完善 #### 配套软件标准化 - 监控Agent ##### 需求 - 安装监控所需要的Agent ##### 一键优化脚本 ```shell yum install zabbix-agent zabbix-sender -y ``` #### 配套软件标准化 - 公钥(管理机免密钥) ##### 需求 - 设置管理机(Ansible)的公钥 - 便于上线后,进行个性化配置(配置文件修改) ##### 一键优化脚本 ```shell wget http://cobbler_host/ansible_key -O /tmp/ansible_key cat /tmp/ansible_key >> /home/ding/.ssh/authorized_keys rm -f /tmp/ansible_key ```