標籤:uil idf 列表 down $? script markdown chkconfig server
centos把http、mysql等加入開機啟動原創 2016年10月14日 22:48:36
有時因為各種原因,需要重啟伺服器,重啟後發現網站打不開了,八成是服務沒有開啟,整理了下把服務加入開機啟動的命令,如下:
1.查看開機啟動項:
chkconfig --list
這裡看到httpd和mysqld未設定開機自動啟動
2.設定開機啟動:
chkconfig httpd on
再次查看結果:
3.如果在列表裡找不到要啟動的服務,則手動添加上去:
chkconfig --add sveserve
4.取消開機啟動:
chkconfig httpd off
還有一種方式,直接修改/etc/rc.d/rc.local 檔案,添加命令:
/etc/rc.d/init.d/mysqld start...
設定memcached為開機啟動項:
在/etc/rc.d/init.d/下建立指令檔,命名為memcached,把以下代碼copy進去儲存
#! /bin/bash # # memcached start/stop the memcached daemon # # chkconfig: 35 80 70 # description: memcached is a memory cache server. # prog="memcached" exec=/usr/local/memcached/bin/memcached lockfile=/var/lock/subsys/memcached # source function library. . /etc/rc.d/init.d/functions start() { if [ $UID -ne 0 ]; then echo "User has insufficient privilege." exit 4 fi [ -x $exec ] || exit 5 echo -n $"starting $prog: " daemon $exec -u root -d -P /var/run/memcached.pid retval=$? echo [ $retval -eq 0 ] && touch $lockfile } stop() { if [ $UID -ne 0 ]; then echo "User has insufficient privilege." exit 4 fi echo -n $"Stopping $prog: " if [ -n "`pidfileofproc $exec`" ]; then killproc $exec else failure $"stopping $prog" fi retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile } restart() { stop start } rh_status() { # run checks to determine if the service is running or use generic status status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in "start") rh_status_q && exit 0 $1 ;; "stop") rh_status_q || exit 0 $1 ;; "restart") rh_status_q || exit 7 $1 ;; "status") rh_status ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 2 ;; esac exit $?
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
添加到開機啟動項:#chkconfig --add memcached
查看啟動項:#chkconfig --list memcached
centos把http、mysql等加入開機啟動