Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1670493
  • 博文数量: 636
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3950
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-06 21:58
个人简介

博客是我工作的好帮手,遇到困难就来博客找资料

文章分类

全部博文(636)

文章存档

2024年(5)

2022年(2)

2021年(4)

2020年(40)

2019年(4)

2018年(78)

2017年(213)

2016年(41)

2015年(183)

2014年(66)

我的朋友

分类: 服务器与存储

2014-11-25 17:47:26

redhat的启动方式和执行次序是
  加载内核
  执行init程序
  /etc/rc.d/rc.sysinit # 由init执行的第一个脚本
  /etc/rc.d/rc $RUNLEVEL # $RUNLEVEL为缺省的运行模式
  /etc/rc.d/rc.local     #相应级别服务启动之后、在执行该文件(其实也可以把需要执行的命令写到该文件中)
  /sbin/mingetty # 等待用户登录


在Redhat中,/etc/rc.d/rc.sysinit主要做在各个运行模式中相同的初始化工作,包括:
  调入keymap以及系统字体
  启动swapping
  设置主机名
  设置NIS域名
  检查(fsck)并mount文件系统
  打开quota
  装载声卡模块
  设置系统时钟
  等等。


/etc/rc.d/rc则根据其参数指定的运行模式(运行级别,你在inittab文件中可以设置)来执行相应目录下的脚本。
凡是以Kxx开头的,都以stop为参数来调用;
凡是以Sxx开头的,都以start为参数来调用。


调用的顺序按xx从小到大来执行。(其中xx是数字、表示的是启动顺序)
例如,
假设缺省的运行模式是3,/etc/rc.d/rc就会按上述方式调用
/etc/rc.d/rc3.d/下的脚本。


值得一提的是,Redhat中的运行模式2、3、5都把/etc/rc.d/rc.local做为初始化脚本中的最后一个
所以用户可以自己在这个文件中添加一些需要在其他初始化工作之后,登录之前执行的命令。


init在等待/etc/rc.d/rc执行完毕之后
(因为在/etc/inittab中/etc/rc.d/rc的action是wait),
将在指定的各个虚拟终端上运行/sbin/mingetty,等待用户的登录。
至此,LINUX的启动结束。





方法一

将自己写好的脚本或命令写入/etc/rc.local文件中。系统会根据该文件来启动所指定的脚本或命令

 

下面为httpd服务做了一个启动脚本。

功能:在Linux系统启动时检查httpd服务是否启动成功,如果服务已启动,将日志写入log。如果没有启动,则立即启动httpd服务,并将日志写入log。

[web@info data]$ vi/data/http.sh

#/bin/bash

log_file=/data/http_state.log

echo "" >$log_file;

http_status=`netstat -nat|grep 80|awk {print $4}`

port=`echo ${http_status:3:3}`;

#echo $port;

if [ "${port}" == "80" ]; then

              echo "http server already start!" >>$log_file;

   elif [ "${port}" == "" ]; then

              echo "http server stop!" >>$log_file;

              /usr/sbin/httpd  -k stop 2>&/dev/null;

fi

将写好的脚本加入/etc/rc.local中

[web@info data]$ echo "/data/http.sh" >>/etc/rc.local ;tail -1 /etc/rc.local

/data/http.sh

[web@info data]$ cat /data/http_status.log

http server stop!

[web@info data]$ netstat -nat|grep 80

tcp        0      0 :::80                       :::*                        LISTEN 

 

方法二

通过启动脚本来创建一个服务,使用chkconfig来指定启动服务的级别,并在ntsysv工具下加载让其自动运行。

 

[root@info ~]# cp /etc/rc.d/init.d/httpd /etc/init.d/aparche


[root@info ~]# chmod +x /etc/init.d/aparche


[root@info ~]# chkconfig --list aparche


aparche 服务支持 chkconfig,但它在任何级别中都没有被引用(运行“chkconfig --add aparche”)


[root@info ~]# chkconfig --add aparche


[root@info ~]# chkconfig --list aparche


aparche           0:关闭     1:关闭     2:关闭     3:关闭     4:关闭     5:关闭     6:关闭

[root@info ~]# chkconfig --level 2345 aparche on


[root@info ~]# service aparche start


启动 httpd:httpd: Could not determine the servers fully qualified domain name, using 127.0.0.1 for ServerName

                                               [  确定  ]    

[root@info ~]# ntsysv  

lqqqqqqqqqqqqu 服务 tqqqqqqqqqqqqk  

 x                                x  

 x 您想自动启动哪些服务?         x  

 x   [*] aparche                    x  

 x    x 确定 x       x 取消  x    x  

 

方法三

在 /home/用户/.bash_profile文件中 加入脚本或命令。在.bash_profile中加载的脚本或命令只能以单用户login时启动。并不是在Linux启动时启动。


[root@info ~]# cat /home/web/.bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

       . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin   

/usr/sbin/httpd  -k start 2>&/dev/null

阅读(870) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~