Linux环境把Mysql和Apache加入到系统服务里面

MySql加入到系统服务里面

cp  /usr/local/mysql/share/mysql/mysql.server      /etc/init.d/mysql     

#把msql的脚本文件拷到系统的启动目录下

cd /etc/init.d/

chkconfig --add mysql                                #将mysql加到启动服务列表里

chkconfig mysql on                                    #让系统启动时自动打开mysql服务

Apache加入启动项里面:

echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local

Apache加入到系统服务里面:

cp /安装目录下/apache/bin/apachectl /etc/rc.d/init.d/httpd

修改httpd

在文件头部加入如下内容:

###

# Comments to support chkconfig on RedHat Linux

# chkconfig: 2345 90 90

# description:http server

###

保存

在打入

#chkconfig --add httpd

#chkconfig --level 345 httpd on

或者


下面介绍如何把Apache加入到系统服务,用service命令来控制Apache的启动和停止。

## 这里请注意一下!如果Linux服务器上默认安装了httpd的话(用rpm -qa|grep httpd查看),

## 会有 /etc/init.d/httpd 这个脚本文件的,所以你也可以用以下方法直接生成这个文件来覆盖它

## 那么下次就可以用 service httpd start 来启动了

## 如果需要区分开来的话就使用下面的方式
  首先以apachectl脚本为模板生成Apache服务控制脚本:
    grep -v "#" /usr/local/apache-2.2.15/bin/apachectl  > /etc/init.d/apache
   用vi编辑Apache服务控制脚本/etc/init.d/apache:
    vi /etc/init.d/apache
   在文件最前面插入下面的行,使其支持chkconfig命令:
    #!/bin/sh
              # chkconfig: 2345 85 15
              # description: Apache is a World Wide Web server.
   保存后退出vi编辑器,执行下面的命令增加Apache服务控制脚本执行权限:
    chmod  +x  /etc/init.d/apache
   执行下面的命令将Apache服务加入到系统服务:
    chkconfig --add apache
   执行下面的命令检查Apache服务是否已经生效:
    chkconfig --list apache
              命令输出类似下面的结果:
              apache          0:off 1:off 2:on 3:on 4:on 5:on 6:off
       表明apache服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制Apache的启动和停止。
  启动Apache服务:
    service apache start
   停止Apache服务:
       service apache stop
   执行下面的命令关闭开机自启动:
    chkconfig apache off
   执行下面的命令改变开机自启动的运行级别为3、5:
    chkconfig --level 35 apache on

猜你喜欢

转载自zhang1120peng.iteye.com/blog/1000871