濮阳杆衣贸易有限公司

主頁 > 知識庫 > Linux系統(tǒng)中的rc.local自啟動服務(wù)

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

熱門標(biāo)簽:桂林市ai電銷機(jī)器人公司 磁力導(dǎo)航地圖標(biāo)注 地圖標(biāo)注的牌子 地址高德地圖標(biāo)注 商店地圖標(biāo)注外賣入駐 外呼系統(tǒng)怎么弄 制作地圖標(biāo)注 外呼系統(tǒng)鏈接 新科火車站地圖標(biāo)注點(diǎn)

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

本文中假設(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的啟動
2. 關(guān)于rc.d
3. 啟動腳本示例
4. 關(guān)于rc.local
5. 關(guān)于bash啟動腳本
6. 關(guān)于開機(jī)程序的自動啟動


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

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

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

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

S{number}{name}

K{number}{name}

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

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

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


3. 啟動腳本示例

這是一個用來啟動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í)慣問題,不是標(biāo)準(zhǔn)。

各個發(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啟動腳本

/etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

是bash的啟動腳本

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

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

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

/etc/bashrc

~/.bash_profile

~/.bashrc

~/.bash_logout

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

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

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

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

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

6. 關(guān)于開機(jī)程序的自動啟動

系統(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啟動腳本中。

========================================================================
設(shè)置系統(tǒ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

加入自動啟動
# chkconfig –add smsafe

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

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

以后可以用以下命令啟動和停止腳本
# service smsafe start 啟動

# service smsafe stop 停止

=======================================================================
jira 的啟動主要依靠的是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的安裝路徑,沒有的話,將會提示找不到文件

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

 

啟動/etc/init.d/jira start

停止/etc/init.d/jira stop

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

(以Websphere為例子)

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

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

2. 在對應(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的自啟動腳本

1.寫一個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. 如果還要自動啟動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)入

標(biāo)簽:湘西 三門峽 衡陽 衡陽 茂名 六盤水 慶陽 仙桃

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Linux系統(tǒng)中的rc.local自啟動服務(wù)》,本文關(guān)鍵詞  Linux,系統(tǒng),中的,rc.local,自,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Linux系統(tǒng)中的rc.local自啟動服務(wù)》相關(guān)的同類信息!
  • 本頁收集關(guān)于Linux系統(tǒng)中的rc.local自啟動服務(wù)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    江孜县| 福海县| 菏泽市| 广元市| 叙永县| 宁南县| 芜湖县| 阳泉市| 洛隆县| 扎兰屯市| 个旧市| 泗阳县| 丹巴县| 睢宁县| 张家界市| 静海县| 建宁县| 宁南县| 永仁县| 深泽县| 新沂市| 嘉兴市| 文成县| 凤山市| 玉林市| 邵阳市| 东辽县| 娱乐| 汉源县| 武城县| 陈巴尔虎旗| 综艺| 榆中县| 汉川市| 象州县| 金寨县| 屯昌县| 墨脱县| 错那县| 巴青县| 百色市|