最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Linux 添加開機(jī)啟動(dòng)方法(服務(wù)/腳本)

 更新時(shí)間:2019年12月12日 10:57:19   作者:劉_love_田  
這篇文章主要介紹了Linux 添加開機(jī)啟動(dòng)方法(服務(wù)/腳本),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

系統(tǒng)啟動(dòng)時(shí)需要加載的配置文件

/etc/profile、/root/.bash_profile
/etc/bashrc、/root/.bashrc
/etc/profile.d/*.sh、/etc/profile.d/lang.sh
/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)

一、修改開機(jī)啟動(dòng)文件:/etc/rc.local(或者/etc/rc.d/rc.local)

# 1.編輯rc.local文件
[root@localhost ~]# vi /etc/rc.local

# 2.修改rc.local文件,在 exit 0 前面加入以下命令。保存并退出。
/etc/init.d/mysqld start                     # mysql開機(jī)啟動(dòng)
/etc/init.d/nginx start                     # nginx開機(jī)啟動(dòng)
supervisord -c /etc/supervisor/supervisord.conf         # supervisord開機(jī)啟動(dòng)
/bin/bash /server/scripts/test.sh >/dev/null 2>/dev/null

# 3.最后修改rc.local文件的執(zhí)行權(quán)限
[root@localhost ~]# chmod +x /etc/rc.local
[root@localhost ~]# chmod 755 /etc/rc.local

二、自己寫一個(gè)shell腳本

將寫好的腳本(.sh文件)放到目錄 /etc/profile.d/ 下,系統(tǒng)啟動(dòng)后就會(huì)自動(dòng)執(zhí)行該目錄下的所有shell腳本。

三、通過(guò)chkconfig命令設(shè)置

# 1.將(腳本)啟動(dòng)文件移動(dòng)到 /etc/init.d/或者/etc/rc.d/init.d/目錄下。(前者是后者的軟連接)
mv /www/wwwroot/test.sh /etc/rc.d/init.d

# 2.啟動(dòng)文件前面務(wù)必添加如下三行代碼,否側(cè)會(huì)提示chkconfig不支持。
#!/bin/sh             告訴系統(tǒng)使用的shell,所以的shell腳本都是這樣
#chkconfig: 35 20 80        分別代表運(yùn)行級(jí)別,啟動(dòng)優(yōu)先權(quán),關(guān)閉優(yōu)先權(quán),此行代碼必須
#description: http server     自己隨便發(fā)揮?。?!,此行代碼必須
/bin/echo $(/bin/date +%F_%T) >> /tmp/test.log

# 3.增加腳本的可執(zhí)行權(quán)限
chmod +x /etc/rc.d/init.d/test.sh

# 4.添加腳本到開機(jī)自動(dòng)啟動(dòng)項(xiàng)目中。添加到chkconfig,開機(jī)自啟動(dòng)。
[root@localhost ~]# cd /etc/rc.d/init.d
[root@localhost ~]# chkconfig --add test.sh
[root@localhost ~]# chkconfig test.sh on

# 5.關(guān)閉開機(jī)啟動(dòng) 
[root@localhost ~]# chkconfig test.sh off

# 6.從chkconfig管理中刪除test.sh
[root@localhost ~]# chkconfig --del test.sh

# 7.查看chkconfig管理
[root@localhost ~]# chkconfig --list test.sh

四、自定義服務(wù)文件,添加到系統(tǒng)服務(wù),通過(guò)Systemctl管理

1.寫服務(wù)文件:如nginx.service、redis.service、supervisord.service

[Unit]:服務(wù)的說(shuō)明
Description:描述服務(wù)
After:描述服務(wù)類別

[Service]服務(wù)運(yùn)行參數(shù)的設(shè)置
Type=forking      是后臺(tái)運(yùn)行的形式
ExecStart        為服務(wù)的具體運(yùn)行命令
ExecReload       為服務(wù)的重啟命令
ExecStop        為服務(wù)的停止命令
PrivateTmp=True     表示給服務(wù)分配獨(dú)立的臨時(shí)空間
注意:?jiǎn)?dòng)、重啟、停止命令全部要求使用絕對(duì)路徑

[Install]        服務(wù)安裝的相關(guān)設(shè)置,可設(shè)置為多用戶
WantedBy=multi-user.target 

2.文件保存在目錄下:以754的權(quán)限。目錄路徑:/usr/lib/systemd/system。如上面的supervisord.service文件放在這個(gè)目錄下面。

[root@localhost ~]# cat /usr/lib/systemd/system/nginx.service
[root@localhost ~]# cat /usr/lib/systemd/system/supervisord.service

3.設(shè)置開機(jī)自啟動(dòng)(任意目錄下執(zhí)行)。如果執(zhí)行啟動(dòng)命令報(bào)錯(cuò),則執(zhí)行:systemctl daemon-reload

設(shè)置開機(jī)自啟動(dòng)
[root@localhost ~]# systemctl enable nginx.service    
[root@localhost ~]# systemctl enable supervisord

停止開機(jī)自啟動(dòng)
[root@localhost ~]# systemctl disable nginx.service
[root@localhost ~]# systemctl disable supervisord

驗(yàn)證一下是否為開機(jī)啟動(dòng)
[root@localhost ~]# systemctl is-enabled nginx
[root@localhost ~]# systemctl is-enabled supervisord

4.其他命令

啟動(dòng)nginx服務(wù)
[root@localhost ~]# systemctl start nginx.service

停止nginx服務(wù)
[root@localhost ~]# systemctl start nginx.service

重啟nginx服務(wù)
[root@localhost ~]# systemctl restart nginx.service

查看nginx服務(wù)當(dāng)前狀態(tài)
[root@localhost ~]# systemctl status nginx.service

查看所有已啟動(dòng)的服務(wù)
[root@localhost ~]# systemctl list-units --type=service

5.服務(wù)文件示例:

# supervisord.service進(jìn)程管理服務(wù)文件
[Unit]
Description=Process Monitoring and Control Daemon  # 內(nèi)容自己定義:Description=Supervisor daemon
After=rc-local.service nss-user-lookup.target

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop= /usr/bin/supervisorctl shutdown 
ExecReload=/usr/bin/supervisorctl reload
Restart=on-failure
RestartSec=42s
KillMode=process 

[Install]
WantedBy=multi-user.target

# nginx.service服務(wù)文件
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target

# redis.service服務(wù)文件
[Unit]
Description=Redis
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecStop=kill -INT `cat /tmp/redis.pid`
User=www
Group=www

[Install]
WantedBy=multi-user.target

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • linux中的軟連接和硬連接詳解

    linux中的軟連接和硬連接詳解

    大家好,本篇文章主要講的是linux中的軟連接和硬連接詳解,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • Linux下Oracle如何導(dǎo)入導(dǎo)出dmp文件詳解

    Linux下Oracle如何導(dǎo)入導(dǎo)出dmp文件詳解

    這篇文章主要給大家介紹了關(guān)于在Linux下Oracle如何導(dǎo)入導(dǎo)出dmp文件的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-07-07
  • 如何在Linux服務(wù)上管理Redis的啟動(dòng)、重啟和關(guān)閉

    如何在Linux服務(wù)上管理Redis的啟動(dòng)、重啟和關(guān)閉

    Redis是一個(gè)高性能的開源鍵值對(duì)存儲(chǔ)數(shù)據(jù)庫(kù),廣泛用于緩存、會(huì)話管理和實(shí)時(shí)數(shù)據(jù)處理等場(chǎng)景,本文將詳細(xì)介紹如何在Linux系統(tǒng)上啟動(dòng)、重啟和關(guān)閉Redis服務(wù),并提供相關(guān)的配置和故障排除技巧,需要的朋友可以參考下
    2024-05-05
  • Apache服務(wù)器中.htaccess的基本配置總結(jié)

    Apache服務(wù)器中.htaccess的基本配置總結(jié)

    這篇文章主要介紹了Apache服務(wù)器中.htaccess的基本配置總結(jié),可以很方便地實(shí)現(xiàn)一些權(quán)限分配等效果,需要的朋友可以參考下
    2015-07-07
  • Ubuntu安裝java的最簡(jiǎn)單的命令行方式(推薦)

    Ubuntu安裝java的最簡(jiǎn)單的命令行方式(推薦)

    這篇文章主要介紹了Ubuntu安裝java的最簡(jiǎn)單的命令行方式的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-11-11
  • 使用光盤配置本地yum源的方法 yum源配置

    使用光盤配置本地yum源的方法 yum源配置

    這篇文章主要介紹了linux使用光盤配置本地yum源的方法
    2014-01-01
  • Apache?Pulsar集群搭建部署詳細(xì)過(guò)程

    Apache?Pulsar集群搭建部署詳細(xì)過(guò)程

    這篇文章主要介紹了Apache?Pulsar集群搭建過(guò)程,搭建Pulsar集群至少需要3個(gè)組件:ZooKeeper集群、BookKeeper集群和Broker集群,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-02-02
  • 判斷Unix系統(tǒng)及庫(kù)文件是32位還是64位的詳解

    判斷Unix系統(tǒng)及庫(kù)文件是32位還是64位的詳解

    這篇文章主要介紹了判斷Unix系統(tǒng)及庫(kù)文件是32位還是64位的的相關(guān)資料,這里整理下查看系統(tǒng)位數(shù)的命令,需要的朋友可以參考下
    2016-11-11
  • Bash中尖括號(hào)的更多使用方法

    Bash中尖括號(hào)的更多使用方法

    這篇文章主要給大家介紹了關(guān)于Bash中尖括號(hào)的更多使用方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • Ubuntu16.04 安裝Teamviewer的教程詳解

    Ubuntu16.04 安裝Teamviewer的教程詳解

    這篇文章主要介紹了Ubuntu16.04 安裝Teamviewer教程,Teamviewer在linux下也可以進(jìn)行安裝,下面給出具體的安裝步驟,需要的朋友可以參考下
    2018-07-07

最新評(píng)論

巩义市| 五家渠市| 枝江市| 克山县| 绍兴县| 拜泉县| 秦皇岛市| 大丰市| 克什克腾旗| 新绛县| 元江| 县级市| 原阳县| 黑龙江省| 新河县| 泸州市| 新源县| 咸宁市| 桐梓县| 太谷县| 康保县| 鲜城| 衡南县| 上栗县| 奇台县| 石屏县| 邵阳市| 泊头市| 保亭| 上思县| 蚌埠市| 西藏| 禹州市| 罗江县| 阿拉善右旗| 涞源县| 德安县| 安化县| 丘北县| 庄浪县| 新干县|