设置开机启动示例:
# touch /etc/init.d/rc.local
设置为可执行:
# chmod +x /etc/init.d/rc.local
用 update-rc.d 设置启动级别:
# update-rc.d rc.local start 99 2 3 4 5 . stop 99 0 1 6 .
为了编辑方便,创建一个链接:
# ln -s /etc/init.d/rc.local /etc/rc.local
# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
## start apache
/usr/local/apache/bin/apachectl start
以下时对与 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 批量导入

linux 开机自启转载的更多相关文章

  1. 如何管理linux开机自启服务

    如何管理linux开机自启服务? 自启动服务非常重要,例如 (1)需要手动添加希望自启的服务,如安装svn后没有自动添加,就需要我们手动加入(2)安装某些程序后,自动加到自启动了,但我们不需要,需要手 ...

  2. Linux开机自启应用&开机执行脚本&监听端口应用挂掉了执行启动脚本

    linux开机自启 背景 目前要部署一个spring boot框架的jar包,实现开机启动项目或者应用挂掉了 执行启动脚本 在root目录下有一个启动项目的脚本: app_start.sh app_s ...

  3. linux开机自启服务

    前言:最近,有一个项目需要用到开机自动启动机房,所以就研究了一下 1.把node的快捷方式放在放在/usr/bin/(环境变量)下面,所有的命令默认是从这里面进行调用的 ln -s /home/too ...

  4. Linux开机自启配置

    1.将自己写好的脚本或命令写入/etc/rc.local文件中.系统会根据该文件来启动所指定的脚本或命令. 例:我有一个脚本:/root/usr/local/scripts/1234.sh 那么直接将 ...

  5. [开机启动]Linux开机自启和运行级别

    嵌入式系统中程序自启动方法 在很多嵌入式系统中,由于可用资源较少,常常在系统启动后就直接让应用程序自动启动,以减少用户操作和节省资源.如何让自己的应用程序自动启动呢?    在Linux系统中,配置应 ...

  6. 关于linux开机自启

    /etc/rc.d/rc.local 是在系统最后启动,必须和其他rc.0 - rcN文件具有755权限

  7. linux 开机自启

    cd /home/dpf 1.vi startup.sh #!/bin/shecho "hello world" >> /home/dpf/test.txt vi mq ...

  8. linux 开机自启脚本

    1.vi /home/dpf/mqtt.sh #!/bin/sh/home/dpf/Desktop/Udp_Single_Async_Mqtt_yuan/hwjc_udp_receive_mqtt & ...

  9. Linux(CentOS6.5)下Nginx注册系统服务(启动、停止、重启、重载等)&设置开机自启

    本文地址http://comexchan.cnblogs.com/ ,作者Comex Chan,尊重知识产权,转载请注明出处,谢谢! 完成了Nginx的编译安装后,仅仅是能支持Nginx最基本的功能, ...

随机推荐

  1. Apche Kafka 的生与死 – failover 机制详解

    转自:http://www.cnblogs.com/fxjwind/p/4972244.html Kafka 作为 high throughput 的消息中间件,以其性能,简单和稳定性,成为当前实时流 ...

  2. SSH框架环境搭建问题:Line: 230 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:230:-1

    只是通过myeclipse搭建一个框架而已 启动tomcat时报错信息: File: SpringObjectFactory.java Method: getClassInstance Line: 2 ...

  3. (笔记)Mysql命令alter add:增加表的字段

    alter add命令用来增加表的字段. alter add命令格式:alter table 表名 add字段 类型 其他; 例如,在表MyClass中添加了一个字段passtest,类型为int(4 ...

  4. discuz X论坛技术架构 MVC结构浅析

    摘自:http://yeyuan.iteye.com/blog/930727 PS:本人刚接触discuz论坛,php水平有限,当中的理解,如有不正确之处,欢迎指出 ----------------- ...

  5. Lucene系列六:Lucene搜索详解(Lucene搜索流程详解、搜索核心API详解、基本查询详解、QueryParser详解)

    一.搜索流程详解 1. 先看一下Lucene的架构图 由图可知搜索的过程如下: 用户输入搜索的关键字.对关键字进行分词.根据分词结果去索引库里面找到对应的文章id.根据文章id找到对应的文章 2. L ...

  6. 使用@Ignore注解

    断续上一节的例子,了解如何使用@Ignore注解.在测试类FirstDayAtSchoolTest中,我们将添加@Ignore注解到testAddPencils()方法.以这种方式,我们期望这个测试方 ...

  7. Java条形码插件

    项目中需要用条形码插件,基于Java平台的 需要比较简单,根据一个12位的数字生成一个条形码图片即可 之前一直用Google的Zxing,因为功能强大,调用简单,网上也有很多资料 后来发现,Zxing ...

  8. RHEL 7 中 systemctl 的用法(替代service 和 chkconfig)

    1.systemctl是RHEL 7 的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体.可以使用它永久性或只在当前会话中启用/禁用服务. systemctl可以列出 ...

  9. R语言绘图时的边界碰撞问题

    当我们在绘图时,经常会遇到这样的问题,添加的文字标记超出了坐标系的问题,导致文字显示不全 比如下面这个例子: plot(c(1,5),c(1,5)) text(5,5.1,"ABCDEF&q ...

  10. mothur summary.seqs 统计fasta文件中每条序列的长度

    在介绍summary.seqs的用法之前,我们首先需要搞清楚两个概念: 1)ambiguous bases 中文叫做模糊碱基,对于DNA序列来说,只有ATCG 4种碱基,在IUPAC定义的碱基标准中, ...