系统初始化脚本 安装centos系统初始

一、初始化系统
1、同步时间
2、关闭selinux
3、禁止root登录
4、清空默认防火墙策略
5、历史命令显示时间及操作用户
6,禁止定时任务发送邮件
7,设置最大文件打开数
8,安装系统功能分析工具及其他

#!/bin/bash

#设置时区并同步时间
#ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#if ! crontab -l | grep ntpdate &>/dev/null ; then
# (echo "* 1 * * * ntpdate time.windows.com >/dev/null 2>&1";crontab -l ) | crontab
#fi
#关闭selinux
#sed 's/SELIUNX=permissive/SELINUX=disabled/g' /etc/selinux/config &>/dev/null
#清空默认防火墙策略
#if grep "7.[0-9]" /etc/redhat-release &>/dev/null ;then
# iptables -F
# echo "firewalld 默认策略以清空"
#elif grep "6.[0-9]" /etc/redhat-release &>/dev/null ;then
# iptables -F
# echo "iptbales 默认策略已经清空"
#fi
#历史命令显示操作时间及用户
#if ! grep HISTTIMEFORMAT /etc/bashrc;then
# echo 'export HISTTMEFORMAT="%F %T `whoami`"' >> /etc/bashrc
# echo "已经成功"
#fi
#ssh 超时时间
#if ! grep "TMOUT=600" /etc/profile &>/dev/null;then
# echo "export TMOUT=600" >> /etc/profile
#fi
#禁止root登录
#sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
#禁止定时任务发送邮件
#sed -i 's/^MAILTO=root/MAILTO=""/g' /etc/crontab
#if ! grep "soft nofile 65535" /etc/security/limits.conf &>/dev/null;then
# cat >> /etc/security/limits.conf << EOF
# * soft nofile 65535
# * hard nofile 65535
#EOF
#fi
#安装系统性能分析工具及其他
#yum -y install gcc* make autoconf vim syssata net-tools iostat iftop iotp lrzsz

 

来自B站学习

原文地址:https://www.cnblogs.com/yjc53/p/12870346.html