萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 資料庫 >> MySQL 教學

解決「service mysql3306 does not support chkconfig」:補全 init 腳本標註

錯誤原因

chkconfig 管理服務需 init 腳本包含特定註釋標籤,缺失則報錯。

修正步驟

  1. 編輯啟動腳本:vi /etc/init.d/mysql3306
  2. 在 #!/bin/sh 之後、任何命令之前加入:
    # chkconfig: 2345 10 90
    # description: MySQL 3306 instance
  3. 註釋說明:
    • 2345:啟動運行級(2=多用戶無網、3=多用戶有網、4=保留、5=圖形界面)。
    • 10:啟動優先級(0-100,數字越小越早啟動)。
    • 90:停止優先級(數字越大越晚停止)。
  4. 註冊並啟用:
    chkconfig --add mysql3306
    chkconfig --level 2345 mysql3306 on
    service mysql3306 start

運行級別對照表

級別名稱描述
0Halt關機
1Single User單用戶維護模式
2Multi-user No Network無網絡多用戶命令行
3Multi-user Network有網絡多用戶命令行(伺服器常用)
4Unused保留
5Graphical圖形界面多用戶
6Reboot重啟

通用模板(適用任何自定義服務)

#!/bin/bash
# chkconfig: 2345 80 20
# description: Custom Service Description
# processname: custom_daemon
# config: /etc/custom.conf
# pidfile: /var/run/custom.pid

start() { ... }
stop() { ... }
case "$1" in
  start) start ;;
  stop) stop ;;
  restart) stop; start ;;
  status) status custom_daemon ;;
  *) echo "Usage: $0 {start|stop|restart|status}"; exit 1 ;;
esac
copyright © 萬盛學電腦網 all rights reserved