qqwe 发表于 2019-2-15 13:46:18

Centos7简单初始化脚本

  #!/bin/bash
  #################
  #################
  . ./check_os.sh
  if [ $(id -u) != "0" ] ; then
  printf "Error:You must be root to run this script!\n"
  exit 1
  fi
  [ "${CentOS_ver}" == '7' ] && [ "$(systemctl is-active NetworkManager.service)" == "inactive" ]
  #关闭selinux
  setenforce 0
  sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
  #修改yum源地址
  yum install -y wget curl
  wgethttp://mirrors.aliyun.com/repo/Centos-7.repo
  mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_back
  mv Centos-7.repo/etc/yum.repos.d/CentOS-Base.repo
  yum clean all
  yum makecache
  yum update
  #命令别名
  cat > /etc/profile.d/alias.sh > /etc/security/limits.conf/etc/profile
  #初始化系统时区
  rm -rf /etc/localtime
  ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  # /etc/sysctl.conf
  [ ! -e "/etc/sysctl.conf_bk" ] && /bin/mv /etc/sysctl.conf{,_bk}
  cat > /etc/sysctl.conf /dev/null 2>&1
  apt-get -y install vim ntpdate locales >/dev/null 2>&1
  echo "Installation system tools.------->OK"
  #更新时间
  ntpdate cn.pool.ntp.org >/dev/null 2>&1
  #停止无用的服务
  #/etc/init.d/exim4 stop >/dev/null 2>&1
  #/etc/init.d/nfs-common stop >/dev/null 2>&1
  #/etc/init.d/portmap stop >/dev/null 2>&1
  ##
  #systemctlstop portmap >/dev/null 2>&1
  #systemctlstop exim4 >/dev/null 2>&1
  #systemctlstop nfs-common >/dev/null 2>&1
  #chkconfig --del exim4 && chkconfig exim4 off >/dev/null 2>&1
  #chkconfig --del portmap && chkconfig exim4 off >/dev/null 2>&1
  #chkconfig --del nfs-common&& chkconfig exim4 off >/dev/null 2>&1
  #设置回话自动超时
  echo "export TMOUT=300">>/etc/profile
  #设置登陆提示
  echo "nginx_111" > /etc/issue
  echo "nginx_111" > /etc/redhat-release
  echo "本机仅限本公司员工使用否则追究法律责任" >/etc/motd
  #安装SendEmail发送邮件
  wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
  tar xf sendEmail-v1.56.tar.gz
  mv sendEmail-v1.56 /data/soft/
  #安装chkrootkit命令检测
  yum install -y chkrootkit
  cat > /data/sh/chkrootkit_everydays.sh /dev/null 2>&1") | crontab
  root@centos-mysql01:/data/sh# cat check_os.sh
  #!/bin/bash
  #######################
  ######################
  #判断系统版本
  if [ -e /etc/redhat-release ]; then
  OS=CentOS
  [ ! -e "$(which lsb_release 2>/dev/null)" ] && { yum -y install redhat-lsb-core; clear; }
  system_ver=$(lsb_release -sr | awk -F. '{print $1}')
  elif [ -n "$(grep 'bian' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Debian" ]; then
  OS=Debian
  [ ! -e "$(which lsb_release 2>/dev/null)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
  system_ver=$(lsb_release -sr | awk -F. '{print $1}')
  elif [ -n "$(grep 'Ubuntu' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Ubuntu" -o -n "$(grep 'Linux Mint' /etc/issue)" ]; then
  OS=Ubuntu
  Ubuntu_ver=$(lsb_release -sr | awk -F. '{print $1}')
  else
  echo "${CFAILURE}Does not support this OS, Please contact the author! ${CEND}"
  kill -9 $$
  fi
  THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
  debian和ubunt的后续再写吧



页: [1]
查看完整版本: Centos7简单初始化脚本