轉來轉去,找不到原文..
# uname -a
Linux machine1 2.6.18-164.el5xen #1 SMP Tue Aug 18 15:59:52 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
查看apache/httpd,版本:
# /usr/sbin/httpd -v
Server version: Apache/2.2.3
Server built: Jul 15 2009 09:02:25
或者
# /usr/sbin/apachectl -v
Server version: Apache/2.2.3
Server built: Jul 15 2009 09:02:25
之前一直在說apache,或者httpd;
其實httpd是服務,apache是個類似快捷方式;
但是因為apache太有名,似乎說apache,就是在說httpd服務了。
因此,后文只說httpd服務。
/usr/sbin/apachectl其實是個腳本;
/usr/sbin/httpd 才是真正的程序;
下面回答如何啟動httpd服務?
腳本啟動:
# /usr/sbin/apachectl start
[root@radius guoq] # ps -ef|grep apache
apache 6680 6679 0 09:49 ? 00:00:00 /usr/sbin/httpd -k start
apache 6681 6679 0 09:49 ? 00:00:00 /usr/sbin/httpd -k start
apache 6682 6679 0 09:49 ? 00:00:00 /usr/sbin/httpd -k start
apache 6683 6679 0 09:49 ? 00:00:00 /usr/sbin/httpd -k start
apache 6684 6679 0 09:49 ? 00:00:00 /usr/sbin/httpd -k start
apache 6685 6679 0 09:49 ? 00:00:00 /usr/sbin/httpd -k start
apache 6686 6679 0 09:49 ? 00:00:00 /usr/sbin/httpd -k start
apache 6687 6679 0 09:49 ? 00:00:00 /usr/sbin/httpd -k start
root 6689 5393 0 09:49 pts/1 00:00:00 grep apache
停止就是 # /usr/sbin/apachectl stop;
如果讀一下腳本 /usr/sbin/apachectl, 就會發現兩個小秘密:
1. 腳本接受參數 start,stop,restart,還有 graceful,graceful-stop;
2. 其實,腳本還是把參數傳遞給了 /usr/sbin/httpd;
因此,我們可以
#/usr/sbin/httpd -k start
啟動服務;
#/usr/sbin/httpd -k stop
停止服務;
下面回答如何開機啟動?
如果搜索一下
# find / -name "httpd"
/var/log/httpd
/usr/sbin/httpd
/usr/lib64/httpd
/etc/rc.d/init.d/httpd
/etc/logrotate.d/httpd
/etc/httpd
/etc/sysconfig/httpd
/home/guoq/osrc/tcl8.4.19/tests/httpd
/opt/soft/httpd-2.2.14/httpd
/opt/soft/httpd-2.2.14/.libs/httpd
/opt/apache2.2.14/bin/httpd
我們會發現apache已經給我們准備好了開機啟動腳本,
/etc/rc.d/init.d/httpd
可以檢查它是否在開機啟動列表:
# chkconfig --list | grep httpd
httpd 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
如果需要,可以將它加入開機啟動列表:
#chkconfig --add httpd
或者,從開機列表中刪除:
#chkconfig --del httpd
在我的系統中,它已經在開機啟動列表:
httpd 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
只是它沒有被允許開機自動啟動
我希望它在當前的運行級別下,自動啟動,我最近在學點PHP;
# chkconfig --level 5 httpd on
# chkconfig --list httpd
httpd 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:啟用 6:關閉
wait,我怎么知道我的運行級別?
# runlevel
N 5
全文完。
1)添加程序腳本到/etc/init.d目錄下
sudo cp /home/cnscn/my_servd /etc/init.d/
2)添加到啟動列表
sudo update-rc.d my_servd defaults
3) 就會產生以下連接:
Adding system startup for /etc/init.d/my_servd ...
/etc/rc0.d/K20my_servd -> ../init.d/my_servd
/etc/rc1.d/K20my_servd -> ../init.d/my_servd
/etc/rc6.d/K20my_servd -> ../init.d/my_servd
/etc/rc2.d/S20my_servd -> ../init.d/my_servd
/etc/rc3.d/S20my_servd -> ../init.d/my_servd
/etc/rc4.d/S20my_servd -> ../init.d/my_servd
/etc/rc5.d/S20my_servd -> ../init.d/my_servd
4) 指定啟動、關閉級別 (20表示一個級別) (注意后面的 . )
sudo update-rc.d my_servd start 20 3 4 5 . 在3,4,5級別上啟動
sudo update-rc.d my_servd start 20 0 1 2 6 . 在3,4,5級別上關閉
或
sudo update-rc.d my_servd start 20 3 4 5 . stop 20 0 1 2 6 .
5) 移除服務
sudo update-rc.d -f my_servd remove