人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

Linux系統(tǒng)中的rc.local自啟動(dòng)服務(wù)

發(fā)布日期:2022-03-21 14:11 | 文章來(lái)源:源碼中國(guó)

linux有自己一套完整的啟動(dòng)體系,抓住了linux啟動(dòng)的脈絡(luò),linux的啟動(dòng)過(guò)程將不再神秘。

本文中假設(shè)inittab中設(shè)置的init tree為:

/etc/rc.d/rc0.d
/etc/rc.d/rc1.d
/etc/rc.d/rc2.d
/etc/rc.d/rc3.d
/etc/rc.d/rc4.d
/etc/rc.d/rc5.d
/etc/rc.d/rc6.d
/etc/rc.d/init.d

目錄

1. 關(guān)于linux的啟動(dòng)
2. 關(guān)于rc.d
3. 啟動(dòng)腳本示例
4. 關(guān)于rc.local
5. 關(guān)于bash啟動(dòng)腳本
6. 關(guān)于開(kāi)機(jī)程序的自動(dòng)啟動(dòng)


1. 關(guān)于linux的啟動(dòng)

init是所有進(jìn)程的頂層
init讀取/etc/inittab,執(zhí)行rc.sysinit腳本
(注意文件名是不一定的,有些unix甚至?xí)⒄Z(yǔ)句直接寫在inittab中)

rc.sysinit腳本作了很多工作:

init $PATH

config network

start swap function

set hostname

check root file system, repair if needed

check root space

....


rc.sysinit根據(jù)inittab執(zhí)行rc?.d腳本
linux是多用戶系統(tǒng),getty是多用戶與單用戶的分水嶺
在getty之前運(yùn)行的是系統(tǒng)腳本


2. 關(guān)于rc.d

所有啟動(dòng)腳本放置在 /etc/rc.d/init.d下

rc?.d中放置的是init.d中腳本的鏈接,命名格式是:

S{number}{name}

K{number}{name}

S開(kāi)始的文件向腳本傳遞start參數(shù)

K開(kāi)始的文件向腳本傳遞stop參數(shù)

number決定執(zhí)行的順序


3. 啟動(dòng)腳本示例

這是一個(gè)用來(lái)啟動(dòng)httpd的 /etc/rc.d/init.d/apache 腳本:

代碼:

#!/bin/bash

......

可以看出他接受start,stop,restart,status參數(shù)

然后可以這樣建立rc?.d的鏈接:

代碼:

cd /etc/rc.d/init.d &&

ln -sf ../init.d/apache ../rc0.d/K28apache &&

ln -sf ../init.d/apache ../rc1.d/K28apache &&

ln -sf ../init.d/apache ../rc2.d/K28apache &&

ln -sf ../init.d/apache ../rc3.d/S32apache &&

ln -sf ../init.d/apache ../rc4.d/S32apache &&

ln -sf ../init.d/apache ../rc5.d/S32apache &&

ln -sf ../init.d/apache ../rc6.d/K28apache


4. 關(guān)于rc.local

經(jīng)常使用的 rc.local 則完全是習(xí)慣問(wèn)題,不是標(biāo)準(zhǔn)。

各個(gè)發(fā)行版有不同的實(shí)現(xiàn)方法,可以這樣實(shí)現(xiàn):

代碼:

touch /etc/rc.d/rc.local

chmod +x /etc/rc.d/rc.local

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc1.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc2.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc3.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc4.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc5.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc6.d/S999rc.local

5. 關(guān)于bash啟動(dòng)腳本

/etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

是bash的啟動(dòng)腳本

一般用來(lái)設(shè)置單用戶的啟動(dòng)環(huán)境,也可以實(shí)現(xiàn)開(kāi)機(jī)單用戶的程序,但要明確他們都是屬于bash范疇而不是系統(tǒng)范疇。

他們的具體作用介紹如下:

/bin/bash這個(gè)命令解釋程序(后面簡(jiǎn)稱shell)使用了一系列啟動(dòng)文件來(lái)建立一個(gè)運(yùn)行環(huán)境:
/etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

~/.bash_logout

每一個(gè)文件都有特殊的功用并對(duì)登陸和交互環(huán)境有不同的影響。

/etc/profile 和 ~/.bash_profile 是在啟動(dòng)一個(gè)交互登陸shell的時(shí)候被調(diào)用。

/etc/bashrc 和 ~/.bashrc 是在一個(gè)交互的非登陸shell啟動(dòng)的時(shí)候被調(diào)用。

~/.bash_logout 在用戶注銷登陸的時(shí)候被讀取

一個(gè)交互的登陸shell會(huì)在 /bin/login 成功登陸之后運(yùn)行。一個(gè)交互的非登陸shell是通過(guò)命令行來(lái)運(yùn)行的,如[prompt]$/bin/bash。一般一個(gè)非交互的shell出現(xiàn)在運(yùn)行 shell腳本的時(shí)候。之所以叫非交互的shell,是因?yàn)樗辉诿钚猩系却斎攵皇菆?zhí)行腳本程序。

6. 關(guān)于開(kāi)機(jī)程序的自動(dòng)啟動(dòng)

系統(tǒng)腳本可以放置在/etc/rc.d/init.d中并建立/etc/rc.d/rc?.d鏈接,也可以直接放置在/etc/rc.d/rc.local中。

init.d腳本包含完整的start,stop,status,reload等參數(shù),是標(biāo)準(zhǔn)做法,推薦使用。

為特定用戶使用的程序(如有的用戶需要使用中文輸入法而有的不需要)放置在~/中的bash啟動(dòng)腳本中。

========================================================================
設(shè)置系統(tǒng)自動(dòng)啟動(dòng)
在/etc/init.d/下創(chuàng)建smsafe文件

內(nèi)容:
#!/bin/bash
# chkconfig: 35 95 1
# description: script to start/stop smsafe
case $1 in
start)
sh /opt/startsms.sh
;;
stop)
sh /opt/stopsms.sh
;;
*)
echo "Usage: $0 (start|stop)"
;;
esac
更改權(quán)限
# chmod 775 smsafe

加入自動(dòng)啟動(dòng)
# chkconfig –add smsafe

查看自動(dòng)啟動(dòng)設(shè)置
# chkconfig –list smsafe

smsafe 0:off 1:off 2:off 3:on 4:off 5:on 6:off

以后可以用以下命令啟動(dòng)和停止腳本
# service smsafe start 啟動(dòng)

# service smsafe stop 停止

=======================================================================
jira 的啟動(dòng)主要依靠的是bin目錄下的catalina.sh腳本,提供了如init腳本的start,stop等參數(shù)

#!/bin/bash

#

# chkconfig: 2345 85 15

# description: jira

# processname: jira

# source function library

. /etc/init.d/functions

#下面一行比較重要,為jira的安裝路徑,沒(méi)有的話,將會(huì)提示找不到文件

CATALINA_HOME="/var/www/jira"

RETVAL=0

start() {

echo -n $"Starting jira services: "

. /var/www/jira/bin/catalina.sh start

RETVAL=$?

echo

}

stop() {

echo -n $"Shutting down jira services: "

. /var/www/jira/bin/catalina.sh stop

RETVAL=$?

echo

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart|reload)

stop

start

;;

status)

status jira

RETVAL=$?

;;

*)

echo $"Usage: $0 {start|stop|restart|status}"

exit 1

esac

exit $RETVAL

-------------------------------

保存為/etc/init.d/jira

然后利用chkconfig --add jira

OK

啟動(dòng)/etc/init.d/jira start

停止/etc/init.d/jira stop

=======================================================================

(以Websphere為例子)

1. 在/etc/rc.d/init.d目錄下新建啟動(dòng)腳本startWebsphere,鍵入以下內(nèi)容:
#!/bin/sh
/opt/WebSphere/AppServer/bin/startServer.sh server1

修改該文件的權(quán)限:
chmod 755 startWebsphere

2. 在對(duì)應(yīng)的目錄下建立軟連接(假設(shè)系統(tǒng)默認(rèn)進(jìn)入X11)
cd /etc/rc.d/rc5.d
ln -s ../init.d/startWebsphere S99startWebsphere

3. 重啟系統(tǒng)即可

=======================================================================
linux下oracle的自啟動(dòng)腳本

1.寫一個(gè)StartOracle.sql,假設(shè)放在/目錄下
vi /StartOracle.sql加入如下兩行保存
startup
exit

2.配置/etc/rc.local
vi /etc/rc.local加入如下內(nèi)容,保存
su - oracle -c '$ORACLE_HOME/bin/lsnrctl start'
su - oracle -c '$ORACLE_HOME/bin/sqlplus "/as sysdba" @/StartOracle.sql'

3. 如果還要自動(dòng)啟動(dòng)oracle enterprise manager(em)和isqlplus可以如下配置
vi /etc/rc.local 加入:
su - oracle -c '$ORACLE_HOME/bin/emctl start dbconsole'
su - oracle -c '$ORACLE_HOME/bin/isqlplusctl start'

要知道em和isqlplus等使用的端口可以查詢文件:
$ORACLE_HOME/install/portlist.ini(以oracle 10.1.0.3為例)

=======================================================================
#root命令行下直接綁定演示:
arp -s 192.x.x.x. 00:ea:se綁定.
arp -d 刪除
arp -f 批量導(dǎo)入

美國(guó)快速服務(wù)器

版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開(kāi)通

自選配置、實(shí)時(shí)開(kāi)通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問(wèn)服務(wù)

1對(duì)1客戶咨詢顧問(wèn)

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部