apache安装成为linux的服务,Linux 上服务的安装以及示例:Apache服务的安装

Linux 上服务的安装以及示例:Apache服务的安装(转)

1. chkconfig脚本格式:

#!/bin/sh

#chkconfig 2345 55 45

#上面为固定格式:2345 表示运行级别,55表示开机执行顺序,45为关机顺序

#description:this is just a demo of chkconfig script

case “$1” in

start)

;;

Stop)

;;

Status)

Echo

;;

*)

Echo “the usage of the script”

Case

2. 然后将脚本保存,并赋予执行权限,再复制到/etc/init.d目录

#chmod a+x

#copy /etc/init.d

3. 使用chkconfig命令添加成服务

#chkconfig --add

#chkconfig --level 35 on

#chkconfig --list

4. 然后就可以通过service命令管理了

#service start | stop | status

5. 下面是我写的一个实例脚本,大家可以参考一些格式:

#!/bin/sh

#chkconfig: 2345 99 99

#description:the script to set the network at run level 2345

IN=eth0

OUT=eth1

HOST_NAME=cluster1.yang.com

INIP=192.168.10.10

OUTIP=192.168.136.10

MASK=255.255.255.0

IP=/sbin/ip

IFC=/sbin/ifconfig

ROUTE=/sbin/route

#flush the address

case "$1" in

start)

#echo "flush the address..."

#$IP addr flush dev eth0

#$IP addr flush dev eth1

echo "set the address..."

$IFC $IN $INIP netmask $MASK up

$IFC $OUT $OUTIP netmask $MASK up

echo "set the hostname..."

hostname $HOST_NAME

echo "set the default gateway..."

$IP route flush all

$ROUTE add default gw 192.168.136.2

echo "finshed!!!"

;;

stop)

echo "flush the network setting..."

$IP addr flush dev eth0

$IP addr flush dev eth1

echo "flush finshed!!!"

;;

status)

echo "hostname is $HOST_NAME"

$IFC eth0

$IFC eth1

;;

*)

echo "requires start,stop or status"

;;

esac

--------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------

在Linux中chkconfighttpd任务添加,Apache服务器的最新稳定发布版本是httpd-2.2..0,官方下载地址是:http://httpd.apache.org/download.cgi。我们通过下面的步骤来快速的搭建一个web服务器。

1、下载源码文件httpd-2.2.0.tar.gz 到linux服务器的某个目录。

2、解压文件 # tar zxvf httpd-2.2.0.tar.gz .

3、配置 # ./configure –refix=/usr/local/apache //指定安装目录,以后要删除安装就只需删除这个目录。

4、编译和安装。 # make ; make install .

5、编写启动脚本,把它放到目录 /etc/rc.d/init.d/里,这里取名为httpd,其内容如下:

#!/bin/bash

#description:http server

#chkconfig: 235 98 98

case "$1" in

start)

echo "Starting Apache daemon..."

/usr/local/apache2/bin/apachectl -k start

;;

stop)

echo "Stopping Apache daemon..."

/usr/local/apache2/bin/apachectl -k stop

;;

restart)

echo "Restarting Apache daemon..."

/usr/local/apache2/bin/apachectl -k restart

;;

status)

statusproc /usr/local/apache2/bin/httpd

;;

*)

echo "Usage: $0 {start|stop|restart|status}"

exit 1

;;

Esac

注意:#description:http server 这一行必须加上,否则在执行命令

# chkconfig –add httpd

时会出现“service apache does not support chkconfig”的错误报告。

#chkconfig: 2345 98 98 表示在执行命令

# chkconfig –add httpd 时会在目录 /etc/rc2.d/ 、/etc/rc3.d/ /etc/rc5.d 分别生成文件 S98httpd和 K98httpd。这个数字可以是别的。

6、执行命令 # chkconfig –add httpd ,进入目录/etc/rc3.d/检查是否生成文件 S98httpd及K98httpd.

7、启动服务 # service httpd start .

Kyle Wang

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值