Centos 系統初始化管理指令碼

來源:互聯網
上載者:User

標籤: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




說下指令碼的商務邏輯吧:

  1. 判斷使用者身份 [非root退出指令碼]

  2. 檢測伺服器網路是否正常 [出錯退出指令碼]

  3. 安裝remi yum源

  4. 關閉selinux

  5. 關閉iptables

  6. 變更SSH連接埠

  7. 更改linux網路核心參數


#其中關閉iptables,變更SSH連接埠,更改linux網路核心參數,暫時沒寫邏輯代碼,周末會更新上

本文出自 “Linux營運” 部落格,轉載請與作者聯絡!

Centos 系統初始化管理指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.