初始化centos7系统

搜集服务器信息:

[root@demo1 ~]# cat /etc/redhat-release && echo "CPU名字及其编号:" `cat /proc/cpuinfo|grep "model name"|head -n 1` && echo "逻辑CPU数量:" `cat /proc/cpuinfo |grep "processor"|wc -l` && fdisk -l|grep /dev/sda | head -n 1 && cat /proc/meminfo | grep MemTotal

修改hostname

hostnamectl set-hostname demo1.changhongit.com

修改IP地址:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

初始化系统:init-centos7

#!/bin/bash


#
# 设置系统参数
#
ulimit_exist=`cat ~/.bash_profile|grep ulimit`
if [ "x$ulimit_exist" = "x" ]; then
echo "设置ulimit......"
echo 'ulimit -n 200000'>>~/.bash_profile
source ~/.bash_profile
else
echo -e "ulimit已设置,Skip$DOTS$OK"
fi


sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
sed -i "s|^#RemoveIPC.*|RemoveIPC=no|g" /etc/systemd/logind.conf
systemctl daemon-reload
systemctl restart systemd-logind




sysctl_exist=`cat /etc/sysctl.conf | grep net.ipv4.tcp_tw_reuse`
if [ "x$sysctl_exist" = "x" ]; then
echo "设置系统参数......"
echo 'net.ipv4.tcp_tw_reuse = 1'>>/etc/sysctl.conf
echo 'net.ipv4.tcp_timestamps = 0'>>/etc/sysctl.conf
echo 'net.ipv4.tcp_tw_recycle = 0'>>/etc/sysctl.conf
echo 'kernel.sem = 250 32000 100 128'>>/etc/sysctl.conf
echo 'fs.file-max = 200000'>>/etc/sysctl.conf
echo 'net.ipv4.ip_local_port_range = 1024 65000'>>/etc/sysctl.conf
echo 'vm.vfs_cache_pressure=200'>>/etc/sysctl.conf
echo "kernel.shmmax=$((`free | grep Mem | awk '{print $2}'`*4/10))" >> /etc/sysctl.conf
echo "kernel.shmall=$((`free | grep Mem | awk '{print $2}'`*4/10))" >> /etc/sysctl.conf
sysctl -p
echo -e "系统参数设置成功$DOTS$OK"
else
echo -e "sysctl.conf已设置,skip$DOTS$OK"
fi
sleep 1


# 设置TERM相关的参数
echo "export TERM=linux">> /etc/profile


# 设置history命令相关的参数
histtimeformat=`grep HISTTIMEFORMAT /etc/profile`
if test "x$histtimeformat" = "x" ; then
# echo "USER_IP=\`who -u am i 2>/dev/null| awk '{print \$NF}'|sed -e 's/[()]//g'\`" >> /etc/profile
echo "export HISTTIMEFORMAT=\"[%F %T] \$LOGNAME \"" >> /etc/profile
echo "HISTTIMEFORMAT 设置成功!"
fi




#
# 安装必要的软件包
#
echo "检测安装必要的软件包......"


yum update -y
echo "开始安装软件包......"
yum -y install kernel-devel kernel-headers libgomp cpp gcc libstdc++-devel gcc-c++ ncurses-devel gdb pkgconfig libidn-devel e2fsprogs-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel zlib-devel openssl-devel bison libxml2-devel libjpeg-devel libXpm gd freetype freetype-devel fontconfig-devel libpng libpng-devel flex readline libtermcap-devel libxslt readline-devel gnutls-devel curl curl-devel sysstat ntp nfs-utils rsync telnet tcpdump lsof dos2unix
yum -y install bison-devel vim portmap unzip zip git postgresql.x86_64 sendmail tree patch
yum -y install iotop iftop yum-utils net-tools git lrzsz expect make cmake sudo libaio-devel wget autoconf automake python-devel bash-completion bridge-util ebtables ethtool ntpdate
echo -e "安装完成!$DOTS$OK"


yum -y install zlib*
yum -y install openssl openssl-devel
yum -y install lrzsz wget
yum update -y nss




# 修改ssh配置UseDNS
sed -i "s|^#UseDNS yes|UseDNS no|g" /etc/ssh/sshd_config


#
# 设置时间同步
#
ntpdate_path=`whereis ntpdate | awk '{print $2}'`
echo "时间同步设置......"
ntp_cmd="${ntpdate_path} -u 10.10.10.7 || ${ntpdate_path} -u 10.10.12.74 || ${ntpdate_path} -u ntp1.aliyun.com"
crontab_ntp=`cat /var/spool/cron/root | grep ntpdate | awk '{print $7}'`
if [ "$crontab_ntp" = "" ]; then
echo "0 6,13,22 * * * ${ntp_cmd}" >> /var/spool/cron/root
crontab /var/spool/cron/root
echo -e "为ntp添加定时计划完成$DOTS$OK"
else
crontab_ntp_usr=`echo "$crontab_ntp" | grep "usr"`
if test "X${crontab_ntp_usr}" = "X";then
sed -i "/ntpdate/c 0 6,13,22 * * * ${ntp_cmd}" /var/spool/cron/root
echo -e "为ntp添加定时计划完成$DOTS$OK"
fi
fi
echo -e "时间同步设置完成$DOTS$OK"


source_exist=`cat /etc/rc.local |grep "source /etc/profile"`


if [ "x$source_exist" != "x" ]; then
echo -e "source_exist=$source_exist $DOTS$WRONG"
else
echo "source /etc/profile">>/etc/rc.local
fi


# 修改limits.conf的配置
cd /etc/security
limit_set=`grep 200000 limits.conf`
if test "x$limit_set" != "x"
then
echo "limits.conf Already set!"
else
echo "* soft nofile 200000" >> limits.conf
echo "* hard nofile 200000" >> limits.conf
echo "* soft nproc 65535" >> limits.conf
echo "* hard nproc 65535" >> limits.conf
echo "Set OK!"
fi


if [ -f /etc/security/limits.d/20-nproc.conf ]; then
is_set=`cat /etc/security/limits.d/20-nproc.conf|grep "nproc 65535"|wc -l`
if [ ${is_set} -ne 2 ]; then
echo "* soft nproc 65535" > /etc/security/limits.d/20-nproc.conf
echo "* hard nproc 65535" >> /etc/security/limits.d/20-nproc.conf
echo "root soft nproc unlimited" >> /etc/security/limits.d/20-nproc.conf
fi
fi


echo "\$SystemLogRateLimitInterval 60" >> /etc/rsyslog.conf
echo "\$SystemLogRateLimitBurst 3000" >> /etc/rsyslog.conf
systemctl restart rsyslog 
echo -e "设置rsyslog.conf$DOTS$OK"




echo -e "设置/etc/crontab"
echo "01 * * * * root run-parts /etc/cron.hourly">>/etc/crontab
echo "02 0 * * * root run-parts /etc/cron.daily">>/etc/crontab
echo "22 4 * * 0 root run-parts /etc/cron.weekly">>/etc/crontab
echo "42 4 1 * * root run-parts /etc/cron.monthly">>/etc/crontab

你可能感兴趣的:(服务器,linux,centos)