CENTOS 6.6初始化SHELL腳本


這個腳本是在剛安裝完CENTOS6.6後可能需要進行的操作。在學習CENTOS的時候,可以先運行這個腳本進行一些配置,可以幫助你不會被這些防火牆 yum selinux ip這些困擾。

#!/bin/bash
 
#判斷是不是root用戶
if [[ "$(whoami)" != "root" ]]; then
 
    echo "please run this script as root ." >&2
    exit 1
fi
 
echo -e "\033[31m 這個是系統初始化腳本,請慎重運行!確定使用請註釋指定行 \033[0m"


#請註釋下一行
exit 1;

#關閉SELINUX
selinux(){
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
setenforce 0
}

#設置動態ip
ip(){
     sed -i 's/ONBOOT=no/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-eth0
     service network restart > /dev/null
}
 
#設置時間時區同步
zone_time(){
    rm -rf /etc/localtime
    ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 
    # 更新時間
    /usr/sbin/ntpdate pool.ntp.org
    echo '*/5 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1' > /var/spool/cron/root;chmod 600 /var/spool/cron/root
    /sbin/service crond restart
}

#配置yum源
yum_update(){
    yum -y install wget
    cd /etc/yum.repos.d/
    mkdir bak
    mv ./*.repo bak
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

}
 
# 清空iptables規則並保存
iptables(){
    iptables -F
    iptables -P INPUT ACCEPT
    iptables -P OUTPUT ACCEPT
    service iptables save
}

other(){
# 可以在這裏定製你想做的something
}
 
main(){
    ip
    yum_update
    selinux
    zone_time
    iptables
    other
}

main


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章