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,其內容如下:
- #!/bin/bash
- #description:http server
- #chkconfig: 235 98 98
- case "$1" in
- start)
- echo "Starting Apache daemon..."
- /usr/local/apache2/bin/apachectl -k start
- ;;
- stop)
- echo "Stopping Apache daemon..."
- /usr/local/apache2/bin/apachectl -k stop
- ;;
- restart)
- echo "Restarting Apache daemon..."
- /usr/local/apache2/bin/apachectl -k restart
- ;;
- status)
- statusproc /usr/local/apache2/bin/httpd
- ;;
- *)
- echo "Usage: $0 {start|stop|restart|status}"
- exit 1
- ;;
- 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