国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Linux:Ubuntu 20.04 —添加開機(jī)啟動(服務(wù)/腳本)

這篇具有很好參考價值的文章主要介紹了Linux:Ubuntu 20.04 —添加開機(jī)啟動(服務(wù)/腳本)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

本文章向大家介紹Linux Ubuntu 20.04 —添加開機(jī)啟動(服務(wù)/腳本),主要包括Linux Ubuntu 20.04 —添加開機(jī)啟動(服務(wù)/腳本)使用實(shí)例、應(yīng)用技巧、基本知識點(diǎn)總結(jié)和需要注意事項(xiàng),具有一定的參考價值,需要的朋友可以參考一下。


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

/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ī)啟動文件:/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ī)啟動
/etc/init.d/nginx start                                          # nginx開機(jī)啟動
supervisord -c /etc/supervisor/supervisord.conf                #supervisord開機(jī)啟動
/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

二、自己寫一個shell腳本
將寫好的腳本(.sh文件)放到目錄 /etc/profile.d/ 下,系統(tǒng)啟動后就會自動執(zhí)行該目錄下的所有shell腳本。
三、通過chkconfig命令設(shè)置

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

# 2.啟動文件前面務(wù)必添加如下三行代碼,否側(cè)會提示chkconfig不支持。
#!/bin/sh                          告訴系統(tǒng)使用的shell,所以的shell腳本都是這樣
#chkconfig: 35 20 80              分別代表運(yùn)行級別,啟動優(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ī)自動啟動項(xiàng)目中。添加到chkconfig,開機(jī)自啟動。
[root@localhost ~]# cd /etc/rc.d/init.d
[root@localhost ~]# chkconfig --add test.sh
[root@localhost ~]# chkconfig test.sh on

# 5.關(guān)閉開機(jī)啟動
[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ù),通過Systemctl管理
1.寫服務(wù)文件:如nginx.service、redis.service、supervisord.service

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

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

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

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

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

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

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

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

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

4.其他命令

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

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

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

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

# 查看所有已啟動的服務(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

Linux Ubuntu 20.04 —添加開機(jī)啟動(服務(wù)/腳本) - 簡書文章來源地址http://www.zghlxwxcb.cn/news/detail-498465.html

到了這里,關(guān)于Linux:Ubuntu 20.04 —添加開機(jī)啟動(服務(wù)/腳本)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 虛擬機(jī)ubuntu20.04擴(kuò)容時遇到的問題及解決方法(包含fdisk打不開、開機(jī)黑屏無法啟動及一種擴(kuò)容辦法)

    虛擬機(jī)ubuntu20.04擴(kuò)容時遇到的問題及解決方法(包含fdisk打不開、開機(jī)黑屏無法啟動及一種擴(kuò)容辦法)

    在創(chuàng)建ubuntu虛擬機(jī)的前期,默認(rèn)選擇了ubuntu的內(nèi)存為20G,但是用了沒多長時間就經(jīng)常提示我內(nèi)存不足,我也沒怎么在意。直到某一天我發(fā)現(xiàn)代碼都保存不了了。ubuntu擴(kuò)容迫在眉睫。、 擴(kuò)容的具體過程我這一次沒有記錄下來,著重講一下遇到的問題,相信我之后還會擴(kuò)容,后續(xù)

    2024年02月08日
    瀏覽(462)
  • ubuntu20.04開機(jī)黑屏只有光標(biāo)閃爍

    ubuntu20.04開機(jī)黑屏只有光標(biāo)閃爍

    前情介紹? ??????? 最初遇到這個問題我一直以為開機(jī)黑屏,然而就那一瞥讓我發(fā)現(xiàn)了事情沒那么簡單,原來還有一個小小的光標(biāo)閃爍,ok,活來了! 原因分析 ??????? 1、硬件可能連接不正確 ??????? 2、驅(qū)動安裝的有問題(我遇到的是這個問題) ??????? 3、安裝

    2024年04月27日
    瀏覽(370)
  • ubuntu20.04開機(jī)界面黑屏,只有一個光標(biāo)閃爍

    ubuntu20.04開機(jī)界面黑屏,只有一個光標(biāo)閃爍

    接下來我就把我的解決方法完整的發(fā)出來,因?yàn)槲乙彩欠浅5慕^望,終于在不斷嘗試中解決了問題 首先開機(jī)界面就是這個東西,一直卡在這不動了,原因就是,內(nèi)存被用完了,無法加載出圖形化界面 解決方法: 1.重啟虛擬機(jī),注意在重啟之后,要不停的去按ctrl+alt+f3,因?yàn)槭?/p>

    2023年04月27日
    瀏覽(23)
  • Ubuntu20.04開機(jī)閃光標(biāo)進(jìn)不去圖形界面

    Ubuntu20.04開機(jī)閃光標(biāo)進(jìn)不去圖形界面

    (一)實(shí)驗(yàn)室電腦 ??????? 默認(rèn)進(jìn)入系統(tǒng)的方式黑屏閃爍光標(biāo),重啟后進(jìn)入最新的recover模式中進(jìn)行修復(fù),發(fā)現(xiàn)還是進(jìn)不去圖形界面,再重啟進(jìn)入低版本的內(nèi)核可以正常進(jìn)入,說明是內(nèi)核版本太高,與NVIDIA驅(qū)動不匹配導(dǎo)致的問題。這里的解決方案選擇的是通過較低版本的內(nèi)

    2024年02月15日
    瀏覽(22)
  • 27. Ubuntu 20.04 開機(jī)自動掛載文件/etc/fstab

    27. Ubuntu 20.04 開機(jī)自動掛載文件/etc/fstab

    不同于熱插拔的設(shè)備,對于硬盤可能需要長期掛載在系統(tǒng)下,所以如果每次開機(jī)都去手動mount是非常痛苦的,當(dāng)然Ubuntu系統(tǒng)的GNOME桌面自帶的gvfsd也會幫你自動掛載,但是指向的路徑卻是按照uuid命名的,這是極其痛苦的,所以希望開機(jī)就可以自動掛載硬盤到指定路徑。 系統(tǒng)開

    2024年02月06日
    瀏覽(19)
  • 虛擬機(jī)Ubuntu20.04 網(wǎng)絡(luò)連接器圖標(biāo)開機(jī)不顯示怎么辦
  • Ubuntu 20.04 中安裝docker一鍵安裝腳本

    直接上腳本,依次執(zhí)行如下命令即可 install docker operation system Ubuntu 18.04+ ways1 : wget https://github.com/grant-tt/docker/blob/main/docker_install.sh bash docker_install.sh ways2: wget http://apollo-pkg-beta.bj.bcebos.com/docker_install.sh bash docker_install.sh

    2024年02月13日
    瀏覽(95)
  • Ubuntu Server 20.04 網(wǎng)卡啟動及配置

    由于網(wǎng)絡(luò)環(huán)境問題,聯(lián)網(wǎng)安裝會導(dǎo)致報錯,故在安裝期間disable了所有網(wǎng)卡,下面記錄裝好之后打開的過程。 得到本機(jī)的所有網(wǎng)卡信息,例如我這邊網(wǎng)卡為eth0 將上述網(wǎng)卡名稱填入 把up換成down是關(guān)掉 ubuntu server 20.04 采用讀yaml配置文件的方式修改網(wǎng)卡配置,文件在/etc/netplan/下,

    2024年02月11日
    瀏覽(22)
  • Linux | Ubuntu20.04系統(tǒng)使用命令從移動硬盤/U盤拷貝文件到服務(wù)器上

    *確認(rèn)自己移動硬盤、U盤的格式,本文為exfat格式 查看disk默認(rèn)位置 查看最后的位置,我的顯示為 Device, 位置為 /dev/sdb1 ,2048, (后面省略) *注意:此時無法直接查看硬盤內(nèi)容 進(jìn)入Linux系統(tǒng)主界面,如果是user的話,獲取管理員權(quán)限 掛載移動硬盤/U盤 命令如下,其中/dev/sdb1為disk默

    2024年02月14日
    瀏覽(28)
  • ubuntu20.04以及更高版本下docker添加國內(nèi)鏡像

    ubuntu20.04下默認(rèn)是snap安裝的docker。安裝位置和apt安裝的不一樣。所以daemon.json的位置也不一樣。國內(nèi)網(wǎng)上說的都是往/ect/docker/daemon.json里添加 \\\"registry-mirrors\\\": [ ? ? ? ? \\\"http://hub-mirror.c.163.com\\\", ? ? ? ? \\\"https://docker.mirrors.ustc.edu.cn\\\", ? ? ? ? \\\"https://registry.docker-cn.com\\\" ? ? ] 統(tǒng)統(tǒng)都

    2024年02月11日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包