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 批量导入

Linux的rc.local自启动服务相关推荐

  1. linux centos rc.local 自启动无效 解决方法

    解决方法:加可执行权限 chmod +x /etc/rc.d/rc.local

  2. linux系统rc.local错误,Ubuntu 16.04服务器rc-local服务启动失败,可能是因为这个符号没写...

    Ubuntu 16.04服务器上的网站好久没管,今天发现不能访问了,后来发现是rc-local服务无法启动所致: 运行sudo systemctl status rc-local.service提示如 ...

  3. rc.local自启动学习

    linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘. 本文中假设inittab中设置的init tree为: /etc/rc.d/rc0.d /etc/rc ...

  4. 【Linux】rc.local和rc.d/rc.local的区别|rc.local文件开机不执行

    rc.local和rc.d/rc.local的区别 /etc/rc.d/rc.local 用于添加开机启动命令 /etc/rc.local是/etc/rc.d/rc.local的软连接 rc.loca ...

  5. suse linux 启用rc.local

    用习惯了rc.local,suse linux种默认没有开启,需手动设置如下: 1)建立rc-local.service文件 sudo vi /etc/systemd/system/rc-local. ...

  6. linux修改rc.local权限,Linux 7 的 rc.local 文件需要 添加 +x 权限才会自动执行

    vmware 克隆的虚拟机添加的网关的没有生效,每次重启后都需要手工添加网关. 所以将添加命令写到/etc/rc.local 文件里了. https://www.cndba.cn/dave/artic ...

  7. Linux下rc.local不执行问题

    为什么80%的码农都做不了架构师?>>>    vim /etc/rc.local 你就可看到: 需要给 /etc/rc.d/rc.local 真实文件执行的权限 转载于:https ...

  8. linux 设置开机自启动服务命令,linux开机自启动服务优化设置命令

    1.设置成英文字符,避免出现乱码 [root@xuegod62 ~]# LANG=en 2.两种配置linux开机自启动服务命令: 1) [root@xuegod62 ~]# ntsysv 2) [r ...

  9. Linux之开机自启动服务(两种方式)

    Linux开机启动自启动脚本两种方式 先要了解一下系统启动运行级别,请看这篇文章 链接: Linux之运行级别 rc.local方式 1首先创建一个要自启动的脚本 vi /etc/scripts/cr ...

最新文章

  1. HTTP/TCP/IP协议
  2. iOS APP提交上架流程
  3. Centos sudo添加用户
  4. VTK:Filtering之SurfaceFromUnorganizedPoints
  5. ReactiveLodeBalancerClientFilter响应式负载均衡代理
  6. 第1章 C/C++与开发环境介绍(《C和C++游戏趣味编程》配套教学视频)
  7. AutoIt自动化编程(4)【转】
  8. Centos7配置 SNMP服务(防火墙配置注意)
  9. Reactor | Epoll 模型理解
  10. Android MeasureSpec的理解和源码的解析
  11. hexo+next 给博客添加网易云音乐外链接
  12. P2P业务整体流程图
  13. linux上的python开发工具_linuxpython开发工具,在linux下开发python使用什么工具好
  14. Android系统ANR错误实战分析
  15. 解析双稳态肖特基二极管的设计
  16. C:\WINDOWS\system32\config\systemprofile\Desktop引用了一个不可用的位置
  17. 怎么把ogg音频格式转换为mp3
  18. 车载通信与导航(七):D2D通信详解
  19. 80+的AI音频工具你值得拥有
  20. Docker安装(Alibaba Cloud Linux 3)

热门文章

  1. 学精算的计算机知识,精算学专业学什么 附学习科目和课程
  2. Linux进程间的通信----->共享内存
  3. mysql 导出中间 数据_MYSQL数据库之间的数据导出与导入
  4. PCL调错(2):VTK报错
  5. AI视频行为分析系统项目复盘——技术篇4:deepsort原理图
  6. C++中的vector的用法
  7. 【python】一个目录里面多个python程序文件,统计一下里面有多少行代码。即分别列出:代码、空行、注释的行数。
  8. java 注解继承注解_Java注解合并,注解继承
  9. python获取数据类型_python数据类型详解
  10. Udacity机器人软件工程师课程笔记(三十二) - 卡尔曼滤波器 - 一维卡尔曼滤波器 - 多维卡尔曼滤波器 - 拓展卡尔曼滤波器(EKF)