生产环境配置需要标准化,将常用操作写成脚本用于操作系统的初始化。
本脚本适用于centos7,根据实际需求修改yum源地址和ntp时钟同步源地址后即可使用。
#!/bin/bash# Filename: centos7_init.sh# Revision: 1.0# Date: 2017/xx/xx# Author: xxxx# Email: xxxx@qq.com# Website: no# Description:centos7系统初始化#1.定义配置yum源函数function yum(){mkdir -p /etc/yum.repos.d/bak/usr/bin/mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/baktouch /etc/yum.repos.d/http.repocat > /etc/yum.repos.d/http.repo << EOF[http]name=Serverbaseurl=http://192.168.2.252/centos7.3enabled=1gpgcheck=0EOF}#2.定义配置NTP函数function ntp(){/usr/bin/yum -y install ntp#修改配置文件echo '' >/etc/ntp.confcat >>/etc/ntp.conf << EOFdriftfile /var/lib/ntp/driftrestrict default nomodify notrap nopeer noqueryrestrict 127.0.0.1 restrict ::1server 192.168.2.136includefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitorEOF#同步hwclockcat >>/etc/sysconfig/ntpd</dev/null/usr/bin/systemctl disable chronyd &> /dev/null/usr/bin/systemctl start ntpd &> /dev/null/usr/bin/systemctl enable ntpd &> /dev/null}#3.定义关闭防火墙函数function close_firewalld(){ /usr/bin/systemctl stop firewalld.service &> /dev/null /usr/bin/systemctl disable firewalld.service &> /dev/null}#4.定义关闭selinux函数function close_selinux(){ setenforce 0 sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config}#5.内核调优function optimization(){[ -f /etc/sysctl.conf.bak ] && error_show "sysctl.conf.back is exist."/usr/bin/cp /etc/sysctl.conf /etc/sysctl.conf.bakcat>>/etc/sysctl.conf< > /etc/security/limits.confecho "* hard nofile 65535" >> /etc/security/limits.confecho "* soft nproc 65535" >> /etc/security/limits.confecho "* hard nproc 65535" >> /etc/security/limits.conf}#初始化方法function init(){ yum; ntp; close_firewalld; close_selinux; optimization;}init