標籤:centos 指令碼 bash
系統初始化指令碼可以統一、自動設定,減少人力。
這裡淺談一下yum安裝與源碼編譯安裝,請各位不吝指正。我一直堅持yum安裝,原因如下
一、安裝方便,不需要再花精力考慮依賴問題
二、配置統一,方便後期維護,自動化等
三、方便升級
四、好吧,我是菜雞,我承認了650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0039.gif" alt="j_0039.gif" style="padding:0px;margin:0px;vertical-align:top;border:none;" />
#!/bin/sh#判斷使用者身份username=`whoami`;if [ $username != "root" ]then echo "目前使用者許可權不足,即將退出指令碼"; exit 2;fi#驗證使用者網路echo "檢測網路中...";/bin/ping www.baidu.com -c 2 >> /dev/nullif [ $? != 0 ]then echo "網路無法正常通訊,請檢查網路設定"; exit 3;fiecho "網路正常";sleep 1;#安裝yum remi php源if rpm -qa|grep remi-release >> /dev/null;then echo "remi resource is installed";elseyum_changes="a";version=`cat /etc/issue|head -n 1|awk {‘print $3‘}|tr "." "\n"|head -n 1`if [ $version == 5 ]then rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm http://rpms.famillecollet.com/enterprise/remi-release-5.rpm 2>&1 >> /tmp/sys_log.txt elif [ $version == 6 ]then rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 2>&1 >> /tmp/sys_log.txtfiif [ $? != 0 ]then echo "安裝yum 源失敗,請檢查tmp下的日誌";else echo "yum源已經安裝完畢,請自行配置remi源設定檔,選擇PHP的版本";fifi#詢問使用者是否關閉selinuxselinux_st=`sestatus | awk {‘print $3‘}`if [ $selinux_st != "disabled" ]then se_changes="a"; until [ $se_changes == "yes" ] && [ $se_changes == "no" ] do read -p "當前selinux狀態為開啟,是否要關閉(輸入yes關閉,輸入no不關閉):"se_changes done if [ $se_changes == "yes" ] then sed -i ‘s/^SELINUX=enforcing$/SELINUX=disables/‘ /etc/selinux/config 2>&1 >> /tmp/sys_log.txt if [$? != 0] then echo "關閉selinux中出錯,請查看tmp下的日誌"; fi elif [ $se_changes == "no" ] then echo "你選擇了不關閉selinux"; fielse echo "檢測到selinux已經關閉";fi
說下指令碼的商務邏輯吧:
判斷使用者身份 [非root退出指令碼]
檢測伺服器網路是否正常 [出錯退出指令碼]
安裝remi yum源
關閉selinux
關閉iptables
變更SSH連接埠
更改linux網路核心參數
#其中關閉iptables,變更SSH連接埠,更改linux網路核心參數,暫時沒寫邏輯代碼,周末會更新上
本文出自 “Linux營運” 部落格,轉載請與作者聯絡!
Centos 系統初始化管理指令碼