Linux的rc local自启动服务

linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘。

本文中假设inittab中设置的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. 关于linux的启动
2. 关于rc.d
3. 启动脚本示例
4. 关于rc.local
5. 关于bash启动脚本
6. 关于开机程序的自动启动

1. 关于linux的启动

init是所有进程的顶层
init读取/etc/inittab,执行rc.sysinit脚本
(注意文件名是不一定的,有些unix甚至会将语句直接写在inittab中)

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

init $PATH

config network

start swap function

set hostname

check root file system, repair if needed

check root space

....

rc.sysinit根据inittab执行rc?.d脚本
linux是多用户系统,getty是多用户与单用户的分水岭
在getty之前运行的是系统脚本

2. 关于rc.d

所有启动脚本放置在 /etc/rc.d/init.d下

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

S{number}{name}

K{number}{name}

S开始的文件向脚本传递start参数

K开始的文件向脚本传递stop参数

number决定执行的顺序

3. 启动脚本示例

这是一个用来启动httpd的 /etc/rc.d/init.d/apache 脚本:

代码:

#!/bin/bash

......

可以看出他接受start,stop,restart,status参数

然后可以这样建立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. 关于rc.local

经常使用的 rc.local 则完全是习惯问题,不是标准。

各个发行版有不同的实现方法,可以这样实现:

代码:

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. 关于bash启动脚本

/etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

是bash的启动脚本

一般用来设置单用户的启动环境,也可以实现开机单用户的程序,但要明确他们都是属于bash范畴而不是系统范畴。

他们的具体作用介绍如下:

/bin/bash这个命令解释程序(后面简称shell)使用了一系列启动文件来建立一个运行环境:
/etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

~/.bash_logout

每一个文件都有特殊的功用并对登陆和交互环境有不同的影响。

/etc/profile 和 ~/.bash_profile 是在启动一个交互登陆shell的时候被调用。

/etc/bashrc 和 ~/.bashrc 是在一个交互的非登陆shell启动的时候被调用。

~/.bash_logout 在用户注销登陆的时候被读取

一个交互的登陆shell会在 /bin/login 成功登陆之后运行。一个交互的非登陆shell是通过命令行来运行的,如[prompt]$/bin/bash。一般一个非交互的shell出现在运行 shell脚本的时候。之所以叫非交互的shell,是因为它不在命令行上等待输入而只是执行脚本程序。

6. 关于开机程序的自动启动

系统脚本可以放置在/etc/rc.d/init.d中并建立/etc/rc.d/rc?.d链接,也可以直接放置在/etc/rc.d/rc.local中。

init.d脚本包含完整的start,stop,status,reload等参数,是标准做法,推荐使用。

为特定用户使用的程序(如有的用户需要使用中文输入法而有的不需要)放置在~/中的bash启动脚本中。

========================================================================
设置系统自动启动
在/etc/init.d/下创建smsafe文件

内容:
#!/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
更改权限
# chmod 775 smsafe

加入自动启动
# chkconfig –add smsafe

查看自动启动设置
# 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等参数

#!/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,键入以下内容:
#!/bin/sh
/opt/WebSphere/AppServer/bin/startServer.sh server1

修改该文件的权限:
chmod 755 startWebsphere

2. 在对应的目录下建立软连接(假设系统默认进入X11)
cd /etc/rc.d/rc5.d
ln -s ../init.d/startWebsphere S99startWebsphere

3. 重启系统即可

=======================================================================
linux下oracle的自启动脚本

1.写一个StartOracle.sql,假设放在/目录下
vi /StartOracle.sql加入如下两行保存
startup
exit

2.配置/etc/rc.local
vi /etc/rc.local加入如下内容,保存
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 批量导入

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://www.cnblogs.com/captainbed

原文地址:https://www.cnblogs.com/siwnchs/p/10178462.html

时间: 2024-08-29 14:16:22

Linux的rc local自启动服务的相关文章

rc.local自启动学习

linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘. 本文中假设inittab中设置的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. 关于linux的启动 2. 关于rc.d 3. 启动脚本示例 4. 关于rc

rc.local自启动学习(转)

linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘. 本文中假设inittab中设置的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. 关于linux的启动2. 关于rc.d3. 启动脚本示例4. 关于rc.local5. 关

Linux学习 哪些开机自启动服务是必备的?

和Windows系统一样,Linux服务器运行过程中也会一些没用的软件服务默认运行,这些占用了很多系统资源,也会有安全隐患,所以一般是建议关闭的.那么,工作中Linux主机到底需要有哪些开机自启动服务呢? 新装Linux系统之后,有必要保留的开机自启动服务有5个: ? sshd:远程连接Linux服务器时要用到,所以必须开启,不然就无法提供远程连接服务了. ? rsyslog:日志相关软件,这是操作系统提供的一种机制,系统的守护程序通常会使用rsyslog程序将各种信息写到各个系统日志文件中.

centos7下的/etc/rc.local自启动程序

在centos6中有一个/etc/rc.local的启动文件,只要把需要经常启动的程序添加到此文件下并执行source /etc/rc.local就可以实现开机启动了. 在centos7中不知道也是如此操作吗? [[email protected] ~]# cat /etc/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own sy

linux 重要的开机自启动服务

1.sshd  远程连接 2.rsyslog/syslog    日志相关软件,这是操作系统提供的一种机制,系统的守护程序通常会使用rsyslog程序将各种信息写道各个系统的日志文件中 3.network   若想激活/关闭各个网络接口,需要激活此项 4.crond   周期性服务 5.sysstat 系统监控,cpu使用率,内存等

Linux开机启动文件rc.local无法执行怎么办?

rc.local是Linux系统中的一个重要的开机启动文件,每次开机都要执行这个文件.但是有一些用户的Linux系统无法执行这个文件,并导致了一系列的问题.遇到这个问题我们应该怎么办呢? 在Linux系统中,有一个重要的开机自动启动脚本文件: /etc/rc.local--->/etc/rc.d/rc.local 不小心删除了,然后重新创建了一个,但问题出来了,无法自动执行了. 原因: 开机启动的/etc/rc.d/rc3.d/ 文件夹下的链文件失去效应了,修改下即可. 解决方法: 把/etc/

linux chkconfig添加开机启动服务

--add:增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据: --del:删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据: --level<等级代号>:指定读系统服务要在哪一个执行等级中开启或关毕. 等级代号列表: 等级0表示:表示关机 等级1表示:单用户模式 等级2表示:无网络连接的多用户命令行模式 等级3表示:有网络连接的多用户命令行模式 等级4表示:不可用 等级5表示:带图形界面的多用户

linux的自启动服务脚本的(/etc/rc.d/init.d或者其链接/etc/init.d)

转载地址:http://www.cnblogs.com/diyunpeng/archive/2009/11/11/1600886.html Linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘. 本文中假设inittab中设置的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

linux中一次非常有意思的/etc/rc.local不运行任何脚本故障排查

最近在运维公司一台恒生行情服务器过程中,突然某周一发现之前配置/etc/rc.local中能随机器启动脚本没有随机器启动,但手动执行均正常.根据网上各种眼花缭乱资料,核查相关执行权限都有,但就是不执行,连touch /var/lock/subsys/local都不执行.没办法,想过重装,虽然是虚拟机,克隆安装简单,但感觉如果是物理服务器,那是非常麻烦,故还是希望找到原因.中途考虑过做成服务,在rc5.d中重建链接,都失败了.最后,通过对/var/lock/subsys/随机启动服务进行分析,对比