centos把http、mysql等加入開機啟動

來源:互聯網
上載者:User

標籤:uil   idf   列表   down   $?   script   markdown   chkconfig   server   

centos把http、mysql等加入開機啟動原創 2016年10月14日 22:48:36
  • 標籤:
  • centos /
  • 伺服器 /
  • mysql
  • 2377

有時因為各種原因,需要重啟伺服器,重啟後發現網站打不開了,八成是服務沒有開啟,整理了下把服務加入開機啟動的命令,如下: 
1.查看開機啟動項:

chkconfig --list
  • 1

這裡看到httpd和mysqld未設定開機自動啟動

2.設定開機啟動:

chkconfig httpd on
  • 1

再次查看結果:

3.如果在列表裡找不到要啟動的服務,則手動添加上去:

chkconfig --add sveserve
  • 1

4.取消開機啟動:

chkconfig httpd off
  • 1

還有一種方式,直接修改/etc/rc.d/rc.local 檔案,添加命令:

/etc/rc.d/init.d/mysqld start...
  • 1
  • 2

設定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等加入開機啟動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.