Linux 上服務的安裝以及示例:Apache服務的安裝(轉)

          1. chkconfig腳本格式:
          #!/bin/sh
          #chkconfig 2345 55 45
          #上面為固定格式:2345 表示運行級別,55表示開機執行順序,45為關機順序
          #description:this is just a demo of chkconfig script
          case “$1” in
          start)
          <start-script>
          ;;
          Stop)
          <stop-script>
          ;;
          Status)
          Echo <the information you want to display>
          ;;
          *)
          Echo “the usage of the script”
          Case
          2. 然后將腳本保存,并賦予執行權限,再復制到/etc/init.d目錄
          #chmod a+x <myscript>
          #copy <myscript> /etc/init.d
          3. 使用chkconfig命令添加成服務
          #chkconfig --add <myscript>
          #chkconfig --level 35 <myscript > on
          #chkconfig --list <myscript>
          4. 然后就可以通過service命令管理了
          #service <myscript> start | stop | status
          5. 下面是我寫的一個實例腳本,大家可以參考一些格式:
          #!/bin/sh
          #chkconfig: 2345 99 99
          #description:the script to set the network at run level 2345
          IN=eth0
          OUT=eth1
          HOST_NAME=cluster1.yang.com
          INIP=192.168.10.10
          OUTIP=192.168.136.10
          MASK=255.255.255.0
          IP=/sbin/ip
          IFC=/sbin/ifconfig
          ROUTE=/sbin/route
          #flush the address
          case "$1" in
          start)
          #echo "flush the address..."
          #$IP addr flush dev eth0
          #$IP addr flush dev eth1
          echo "set the address..."
          $IFC $IN $INIP netmask $MASK up
          $IFC $OUT $OUTIP netmask $MASK up
          echo "set the hostname..."
          hostname $HOST_NAME
          echo "set the default gateway..."
          $IP route flush all
          $ROUTE add default gw 192.168.136.2
          echo "finshed!!!"
          ;;
          stop)
          echo "flush the network setting..."
          $IP addr flush dev eth0
          $IP addr flush dev eth1
          echo "flush finshed!!!"
          ;;
          status)
          echo "hostname is $HOST_NAME"
          $IFC eth0
          $IFC eth1
          ;;
          *)
          echo "requires start,stop or status"
          ;;
          esac
          --------------------------------------------------------------------------------------------
          --------------------------------------------------------------------------------------------

          在Linux中chkconfighttpd任務添加,Apache服務器的最新穩定發布版本是httpd-2.2..0,官方下載地址是:http://httpd.apache.org/download.cgi。我們通過下面的步驟來快速的搭建一個web服務器。

          1、下載源碼文件httpd-2.2.0.tar.gz 到linux服務器的某個目錄。
          2、解壓文件 # tar zxvf httpd-2.2.0.tar.gz .
          3、配置 # ./configure –refix=/usr/local/apache //指定安裝目錄,以后要刪除安裝就只需刪除這個目錄。
          4、編譯和安裝。 # make ; make install .
          5、編寫啟動腳本,把它放到目錄 /etc/rc.d/init.d/里,這里取名為httpd,其內容如下:
           

          1. #!/bin/bash  
          2. #description:http server  
          3. #chkconfig: 235 98 98  
          4. case "$1" in  
          5. start)  
          6. echo "Starting Apache daemon..."  
          7. /usr/local/apache2/bin/apachectl -k start  
          8. ;;  
          9. stop)  
          10. echo "Stopping Apache daemon..."  
          11. /usr/local/apache2/bin/apachectl -k stop  
          12. ;;  
          13. restart)  
          14. echo "Restarting Apache daemon..."  
          15. /usr/local/apache2/bin/apachectl -k restart  
          16. ;;  
          17. status)  
          18. statusproc /usr/local/apache2/bin/httpd  
          19. ;;  
          20. *)  
          21. echo "Usage: $0 {start|stop|restart|status}"  
          22. exit 1  
          23. ;;  
          24. Esac  

           

          注意:#description:http server 這一行必須加上,否則在執行命令

           # chkconfig –add httpd

          時會出現“service apache does not support chkconfig”的錯誤報告。

          #chkconfig: 2345 98 98 表示在執行命令

           # chkconfig –add httpd 時會在目錄 /etc/rc2.d/ 、/etc/rc3.d/ /etc/rc5.d 分別生成文件 S98httpd和 K98httpd。這個數字可以是別的。

          6、執行命令 # chkconfig –add httpd ,進入目錄/etc/rc3.d/檢查是否生成文件 S98httpd及K98httpd.
          7、啟動服務 # service httpd start .



          Kyle Wang

          posted on 2013-01-17 10:23 王樹東 閱讀(504) 評論(0)  編輯  收藏 所屬分類: Environment SetupEnvironment Skills

          <2013年1月>
          303112345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          公告

          常用鏈接

          留言簿

          隨筆分類(17)

          隨筆檔案(15)

          文章分類(4)

          文章檔案(5)

          收藏夾(4)

          Algorithm

          Design

          Environment Setup

          Installer

          Maven

          MINA

          OS

          Skills for Java

          VIM

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 杨浦区| 奉贤区| 贡嘎县| 彰化县| 香河县| 彭水| 原平市| 黄梅县| 武义县| 疏附县| 水城县| 剑阁县| 隆尧县| 安丘市| 绥滨县| 呼玛县| 南丹县| 卢氏县| 谷城县| 丰都县| 蓝山县| 耒阳市| 沂南县| 晋江市| 汉沽区| 曲松县| 尤溪县| 西乌| 安多县| 岑溪市| 鸡泽县| 黄平县| 句容市| 芒康县| 南陵县| 丰县| 铅山县| 云林县| 阿城市| 博罗县| 阿合奇县|