Linux配置開機自啟動服務

2021-08-28 21:43:13 字數 1017 閱讀 7526

linux伺服器存在重啟的情況,伺服器重啟後原來在跑的服務就停止了,由於伺服器重啟是個隨機事件,因此需要配置在重啟後自動開啟一些服務。

本篇文章對於linux發行版debian和red hat。

1、配置啟動指令碼

進入目錄: /etc/init.d/ ,編寫要開機啟動的指令碼 custom-service.sh

#!/bin/sh

#chkconfig: 345 95 95

#description: custom-service

sh $rds_home/bin/startup.sh

2、使用chkconfig命令配置新增custom-service.sh至自啟動服務
[root@localhost init.d]# chkconfig --add custom-service.sh

[root@localhost init.d]# chkconfig custom-service.sh on

[root@localhost init.d]# chkconfig custom-service.sh --list

注:該輸出結果只顯示 sysv 服務,並不包含

原生 systemd 服務。sysv 配置資料

可能被原生 systemd 配置覆蓋。

要列出 systemd 服務,請執行 'systemctl list-unit-files'。

檢視在具體 target 啟用的服務請執行

'systemctl list-dependencies [target]'。

custom-service.sh 0:關 1:關 2:開 3:開 4:開 5:開 6:關

[root@localhost init.d]#

3、修改指令碼custom-service.sh檔案許可權
[root@localhost init.d]# chmod 777 custom-service.sh
4、重啟伺服器

開機服務自啟動配置

方法一 etc rc.d rc.local 中增加需要啟動的程式或服務。例如 apache安裝在 usr local www目錄下,若要設定自動啟動服務可用以下命令 vi etc rc.d rc.local 加入 usr local www bin apachectl start 方法二 將程式註冊...

Linux服務開機自啟動

有時候我們需要linux系統在開機的時候自動載入某些指令碼或系統服務 主要用三種方式進行這一操作 ln s 在 etc rc.d rc d目錄中建立 etc init.d 服務的軟鏈結 代表0 6七個執行級別之一 chkonfig 命令列執行級別設定 ntsysv 偽圖形執行級別設定 注意 1.這三...

linux 配置開機自啟動

整理了一下linux作業系統下新增開機自啟動的方法,實驗環境為centos,其他的linux作業系統也一樣 一 新增開機自啟動 1.把開機啟動命令加入到 etc rc.d rc.local中 vi etc rc.d rc.local 新增如下內容 mysqlstart script usr bin ...