centos 系统初始化

#!/bin/bash
# author cfwl create date of 2012-10-21
# blog http://cfwlxf.blog.51cto.com
# source user shell variable
PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
# Source system network library.
. /etc/sysconfig/network
# Source system function library.
. /etc/init.d/functions
SYSTEM_HOSTNAME(){
# Source system network library.
. /etc/sysconfig/network
# Update name of system host
printf "\033[33mplease input system host name:\033[0m " STR
read STR
# Judge system hostname
hostname $STR
sed -i "s/HOSTNAME=$HOSTNAME/HOSTNAME=$STR/" /etc/sysconfig/network
# Judge system hostname if equal user input name
HOSTNAME=$(awk -F '=' '/HOSTNAME/{print $2}' /etc/sysconfig/network)
if [ "$HOSTNAME" = "$STR" ]
then
sleep 2
printf "\033[35msystem host name is update by: $STR\033[0m $str\n"
else
printf "\033[35msystem host name is not update\033[0m\n"
exit 0
fi
}
# Update System SSH Service Port
SYSTEM_SSH_PORT(){
SSH_CONFIG=/etc/ssh/sshd_config
#Backup SSH configuration
cp -a ${SSH_CONFIG} ${SSH_CONFIG}.save
#Chage SSH server of port
sed -i '/^#Port/s/#Port 22/Port 65535/g' $SSH_CONFIG
sed -i '/^#UseDNS/s/#UseDNS yes/UseDNS no/g' $SSH_CONFIG
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' $SSH_CONFIG
sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/g' $SSH_CONFIG
sleep 2
#Prompt user if restart SSH service
printf "\033[32myou need to restart the SSH service,configuration to take effect.
1> Input \"y\", Now restart to SSH service.
2> Input \"n\", Later in the manual restart.
Please input string \"y/n\": \033[0m" RETVAL
read RETVAL
[ "$RETVAL" = "y" ] && sleep 2 && /etc/init.d/sshd restart
[ "$RETVAL" = "n" ] && sleep 2 && action "Later on please manual restart SSH service" true
}
# Close system Selinux and iptables function
SYSTEM_IPV4_FORWARD(){
#Close syetem selinux and iptalbes forward
sed -i '/^SELINUX/s/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
RETVAL=$(awk -F '=' '/^SELINUX=/{print $NF}' /etc/selinux/config)
[ "$RETVAL" = "disabled" ] && sleep 1 && printf "\033[36mSelinux Change [$RETVAL], please restart system by tack effect.\033[0m\n"
sleep 2
#Close syetem iptables forward
/etc/init.d/iptables stop && chkconfig iptables off
}
#Optimizing The System Service and Rsync System Time
CLOSE_SYSTEM_SERVER(){
#Stop All System Serivce
for server in `chkconfig --list | awk '{print $1}'`;do chkconfig $server off;done
#Start Up Assign System Service
for server in sshd messagebus rngd network crond rsyslog irqbalance;do chkconfig --level 35 $server on;done
#Print modify alter of service
RETVAL=$(chkconfig --list | egrep '3:on|5:on' | awk '{print $1}' | xargs)
printf "\033[35mPrint current system auto start of server: $RETVAL\033[0m\n"
#Rsync System Local Time
RETVAL=$(rpm -qa ntp | wc -l)
if [ $RETVAL = 1 ]
then
echo "5 * * * * ntpdate ntp.api.bz > /dev/null 2>&1" >> /var/spool/cron/root
else
yum install ntp
echo "5 * * * * ntpdate ntp.api.bz > /dev/null 2>&1" >> /var/spool/cron/root
fi
}
#Update Yum Source
UPDATE_YUM_SOURCE(){
# Judge YUM_BACK_DIR directory if exist
getDT=`date -d "today" +"%Y%m%d_%H%M%S"`
export getDT=$getDT YUM_BACK_DIR=/etc/yum.repos.d/backup_$getDT/
YUM_DIR=/etc/yum.repos.d/
[ ! -d ${YUM_BACK_DIR} ] && mkdir ${YUM_BACK_DIR}
echo ${YUM_BACK_DIR}
#sleep 1000s cd ${YUM_DIR}
find . -type f -name "*.repo" | xargs mv -t ${YUM_BACK_DIR}
RETVAL=0
#Determine the return value if 0.
[ $? = ${RETVAL} ] && printf "\033[32m
1.Inland 163 yum source
2.Inland sohu yum source
Judge:please input install 163 or sohu yum source:\033[0m" STR
read STR
case "$STR" in
163)
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
RETVAL=0
[ $? = ${RETVAL} ] && printf "\033[35mYum source is download successfully of 163 mirrors.\n\033[0m"
sleep 2
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
yum update
yum makecache
;;
sohu)
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo
RETVAL=0
[ $? = ${RETVAL} ] && printf "\033[35mYum source is download successfully of sohu mirrors.\n\033[0m"
sleep 2
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-*
yum update
yum makecache
;;
*)
echo -e "\033[31m Error: plase you input 163 or sohu.\033[0m"
UPDATE_YUM_SOURCE
exit 0
esac
}
#By the user to enter the digital implementation corresponding function
echo -e "\033[32m ----------------------------------------------------------------------------------------------------------------
| welcome to syetem initialize scripts |
----------------------------------------------------------------------------------------------------------------
|Judge: Scripts Can realize the function as follows: |
|(1)Modification system host name . |
|(2)Close system SELINXU and iptables. |
|(3)Modification SSH service port as configure. |
|(4)Close System Don't use of Service and update system time |
|(5)Update System Yum Source |
----------------------------------------------------------------------------------------------------------------\033[0m"
read -p "Please according number input you want execute of function: " number
case "$number" in
1)
SYSTEM_HOSTNAME
RETVAL=0
[ $? = $RETVAL ] && action "System host name update successfully,please restart system." true
;;
2)
SYSTEM_IPV4_FORWARD
;;
3)
SYSTEM_SSH_PORT
RETVAL=0
[ $? = $RETVAL ] && action "Update System SSH Service Port already successfully." true
;;
4)
CLOSE_SYSTEM_SERVER
RETVAL=0
[ $? = $RETVAL ] && action "Initialize Sytem Service already successfully." true
;;
5)
UPDATE_YUM_SOURCE
RETVAL=0
[ $? = $RETVAL ] && action "Update System Yum Source already successfully." true
;;
*)
printf "\033[36mError: please you input prompt dialog box of number:1-5\033[0m\n"
;;
esac

  

centos 系统初始化的更多相关文章

  1. centos系统初始化流程及实现系统裁剪

    Linux系统的初始化流程: POST:ROM+RAM BIOS: Boot Sequence MBR: 446:bootloader 64: 分区表 2: 5A kernel文件:基本磁盘分区 /s ...

  2. centos系统初始化配置

    .改主机名: sed -i 's#HOSTNAME=.*#HOSTNAME=u05mix06.yaya.corp#g' /etc/sysconfig/network && hostna ...

  3. CentOS系统初始化---不断更新中

    注意EOF不能有空格tab键 #get os version release=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides ...

  4. centos系统初始化脚本

    #!/bin/bash #检测是否为root用户 ];then echo "Must be root can do this." exit fi #检测网络 echo " ...

  5. bash-1 初始化CentOS系统的初始化脚本

    初始化CentOS系统的初始化脚本 #!/bin/bash # #******************************************************************* ...

  6. Centos 7 x64 系统初始化

    前言 Hi,小伙伴们,系统初始化是运维工作中重要的一环,它能有效的提升工作效率,并且是标准化规范化的前提:它能省去要用时再去下载的麻烦,另外,还可以避免因未初始化引起的一些故障问题,可谓好处多多.系统 ...

  7. CentOS系统MySQL双机热备配置

    1  概述 在集成项目中需要应对不同环境下的安装配置,主流操作系统大致可以分为三种:Linux.Windows以及UNIX.其中Linux备受青睐的主要原因有两个: 首先,Linux作为自由软件有两个 ...

  8. CentOS系统下Redis安装和自启动配置的步骤

    相信大家都知道Redis是一个C实现的基于内存.可持久化的键值对数据库,在分布式服务中常作为缓存服务.所以这篇文章将详细介绍在CentOS系统下如何从零开始安装到配置启动服务.有需要的可以参考借鉴. ...

  9. 【linux】系统初始化的shell脚本

    根据参考网上的一些文章,总结出来一个系统初始化的shell脚本 1.初始化脚本 #!/bin/bash cat << EOF +------------------------------ ...

随机推荐

  1. iOS:手势与矩形、点运算相关(18-01-24更)

    1.矩形.点运算 1.获取当前的View在Window的frame 2.包含判断 3.获取点击在响应者 touchesBegan 的位置 4.UIScrollView.UITableView 实时 位 ...

  2. git 设置只输入一次用户名和密码

    https方式每次都要输入密码,非常不爽 按照如下设置可只输入一次 记住密码(默认15分钟): git config --global credential.helper cache 自己定义时间(一 ...

  3. MySQL语句的优化

    1.使用limit 当不需要取出全部数据时,在查询后面加上limit限制. 2.select * 每次看到select * 的时候都需要用怀疑的眼光审视,是不是真的需要返回全部的列. 3.重复查询相同 ...

  4. java学习无止境,工资价更高

    原 推荐10个Java方向最热门的开源项目(8月) 2018年08月28日 17:54:32 SnailClimb在CSDN 阅读数:849   版权声明:本文为博主原创文章,未经博主允许不得转载. ...

  5. tp5多入口配置

    手册里可能有写,但不是特别清晰,在这给个实例,有两种方式: 1.多个入口文件: 将public下的index.php复制一份,粘贴.重命名为对应模块的名字,如admin: 编辑admin.php的内容 ...

  6. PHP常用函数归类【持续整理】

    学习了这么久PHP,基础知识总感觉不牢靠,尤其是数组,字符串函数的应用,全部手敲过次手,做出总结都是基础,在回顾一下吧. 一.PHP基础语法 变量,常量     严格区分大小写,但内置结构或关键字无所 ...

  7. day 33 线程

    1.线程理论 什么是线程:线程是cpu的最小执行单位(实体),进程是操作系统的数据资源分配单位   2.线程的两种创建方式(重点) 查看线程的pid:使用os模块查看id,线程的id应该是相同的 3. ...

  8. Msql浅析-基础命令(二)

    篇幅简介 一.Msql数据类型 1.整型 tinyint,  占 1字节 ,有符号: -128~127,无符号位 :0~255 smallint, 占 2字节 ,有符号: -32768~32767无符 ...

  9. 3.Hadoop测试Yarn和MapReduce

    Hadoop测试Yarn和MapReduce 1.配置Yarn (1)配置ResourceManager 生产环境中,一般是重开一台机器作为ResourceManager,这里我们以Master机器代 ...

  10. go语言带cookie的net客户端请求与[]byte转string

    前些日子参加了一个叫Advent of Code的编程大赛,每天一道题,快活似神仙.这每道题都有自己的拼图数据输入puzzle input,要做题就需要用到该数据,把数据复制过来感觉又太麻烦,于是就兴 ...