如何在CentOS6上搭建一个简单的HTTP服务
直接输入命令 yum install httpd -y
我们来解析一下这个命令,yum是yellowdog updater modified的缩写。它使用中心仓库(repository)管理应用程序之间的相互关系,根据计算出来的软件依赖关系对软件进行升级、安装、删除等操作,减少了CentOS用户一直头痛的依赖关系的问题。一般这类软件通过一个或者多个配置文件描述的仓库的网络地址,通过http或者ftp协议在需要的时候从仓库获取软件信息,下载相关的软件包。这样,本地用户通过建立不同仓库描述说明,在有网络连接时就能方便的进行系统的升级维护工作。
二,配置防火墙
回到我们的教程,安装完成后如果您的系统自带了防火墙功能,那么就需要您执行如下命令 /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
那我们再来解析一下这个命令,-I INPUT所指的是允许数据传入服务器,-p tcp是指允许tcp协议,而后面的dport 80 -j ACCEPT应该很容易理解。整条命令的意思就是允许用户通过80端口的tcp协议传入连接,以达到访问页面的效果。
三,启动服务
接着,我们重启防火墙以使我们刚添加的防火墙规则生效 service iptables restart
然后接着启动apache服务 service httpd start
同样,我不厌其烦的再解析一下service指令,service的英文意思为服务(不是你们想的那个服务),而这个指令的作用就是负责管理CentOS上你安装的或者系统自带的服务。而上面的两条指令如果要解释就是 服务iptables重启 服务httpd开启。多么简单对不对。
接着你就可以将你写好的网页传到目录/var/www/html下了。
dhcp是动态主机配置协议,使用udp协议,主要使用udp67和udp 68号端口
1client端会发送dhcp discover广播包
2dhcp服务器会回应dhcp offer广播包
3client端会发送dhcp request广播包
4dhcp服务器发送dhcp ack广播包
[root@mini ~]# rpm -qa dhcp
[root@mini ~]# cat /etc/centos-release
CentOS release 69 (Final)
[root@mini ~]# uname -r
2632-696el6i686
[root@mini ~]# uname -m
i686
[root@mini ~]# yum install -y dhcp
[root@mini ~]# rpm -qa dhcp
dhcp-411-53P1el6centos1i686
[root@mini ~]# rpm -qc dhcp
/etc/dhcp/dhcpdconf
/etc/dhcp/dhcpd6conf
/etc/openldap/schema/dhcpschema
/etc/portreserve/dhcpd
/etc/sysconfig/dhcpd
/etc/sysconfig/dhcpd6
/etc/sysconfig/dhcrelay
/etc/sysconfig/dhcrelay6
/var/lib/dhcpd/dhcpdleases
/var/lib/dhcpd/dhcpd6leases
[root@mini ~]# cat /etc/dhcp/dhcpdconf
#
# DHCP Server Configuration file
# see /usr/share/doc/dhcp/dhcpdconfsample
# see 'man 5 dhcpdconf'
#
查询dhcp sample文件(dhcpdconfsample文件为dhcp配置文件模板)
# rpm -ql dhcp
配置完成后的文件
[root@mini ~]# cat /etc/dhcp/dhcpdconf
#
# DHCP Server Configuration file
# see /usr/share/doc/dhcp/dhcpdconfsample
# see 'man 5 dhcpdconf'
#
# A slightly different configuration for an internal subnet
subnet 1721610 netmask 2552552550 {
range 17216110 17216130;
option domain-name-servers minilocaldomain;
option domain-name "minilocaldomain";
option routers 1721611;
option broadcast-address 1721611;
default-lease-time 600;
max-lease-time 7200;
}
查看配置是否正确
[root@mini ~]# /etc/initd/dhcpd configtest
Syntax: OK
DHCP启动失败,并查询到如下报错信息(/var/log/messages)
Nov 6 06:37:24 mini dhcpd: No subnet declaration for eth0 (19216828139)
Nov 6 06:37:24 mini dhcpd: Ignoring requests on eth0 If this is not what
Nov 6 06:37:24 mini dhcpd: you want, please write a subnet declaration
Nov 6 06:37:24 mini dhcpd: in your dhcpdconf file for the network segment
Nov 6 06:37:24 mini dhcpd: to which interface eth0 is attached
Nov 6 06:37:24 mini dhcpd:
Nov 6 06:37:24 mini dhcpd:
Nov 6 06:37:24 mini dhcpd: Not configured to listen on any interfaces!
Nov 6 06:37:24 mini dhcpd:
Nov 6 06:37:24 mini dhcpd: This version of ISC DHCP is based on the release available
Nov 6 06:37:24 mini dhcpd: on ftpiscorg Features have been added and other changes
Nov 6 06:37:24 mini dhcpd: have been made to the base software release in order to make
Nov 6 06:37:24 mini dhcpd: it work better with this distribution
Nov 6 06:37:24 mini dhcpd:
Nov 6 06:37:24 mini dhcpd: Please report for this software via the CentOS Bugs Database:
Nov 6 06:37:24 mini dhcpd: http://bugscentosorg/
Nov 6 06:37:24 mini dhcpd:
Nov 6 06:37:24 mini dhcpd: exiting
解决办法:
这是因为DHCP程序发现没有“Not configured to listen on any interfaces”,只需要配置相应的IP到目标网卡中便可以解决这个问题。
[root@mini ~]# ifconfig eth1 1721611/24
[root@mini ~]# /etc/initd/dhcpd start
Nov 6 06:43:11 mini dhcpd: Internet Systems Consortium DHCP Server 411-P1
Nov 6 06:43:11 mini dhcpd: Copyright 2004-2010 Internet Systems Consortium
Nov 6 06:43:11 mini dhcpd: All rights reserved
Nov 6 06:43:11 mini dhcpd: For info, please visit https://wwwiscorg/software/dhcp/
Nov 6 06:43:11 mini dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Nov 6 06:43:11 mini dhcpd: Wrote 0 leases to leases file
Nov 6 06:43:11 mini dhcpd: Listening on LPF/eth1/00:0c:29:c5:2b:7e/1721610/24
Nov 6 06:43:11 mini dhcpd: Sending on LPF/eth1/00:0c:29:c5:2b:7e/1721610/24
Nov 6 06:43:11 mini dhcpd:
Nov 6 06:43:11 mini dhcpd: No subnet declaration for eth0 (19216828139)
Nov 6 06:43:11 mini dhcpd: Ignoring requests on eth0 If this is not what
Nov 6 06:43:11 mini dhcpd: you want, please write a subnet declaration
Nov 6 06:43:11 mini dhcpd: in your dhcpdconf file for the network segment
Nov 6 06:43:11 mini dhcpd: to which interface eth0 is attached
Nov 6 06:43:11 mini dhcpd:
Nov 6 06:43:11 mini dhcpd: Sending on Socket/fallback/fallback-net
[root@mini ~]# cat /var/lib/dhcpd/dhcpdleases
注意:如果Linux开启了防火墙,那么需要对UDP 67和UDP 68放行。或者直接将放火墙关闭
准备前的工作:
1修改selinux配置文件(/etc/sysconfig/selinux) 关闭防火墙
(1)把SELINUX=enforcing注释掉
(2)并添加SELINUX=disabled
2修改防火墙配置文件(/etc/sysconfig/iptables) 开放端口号
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
打开连个常用的端口
如今,Linux在Web应用越来越广,许多企业都采用Linux来搭建Web服务器,这样即节省了购买正版软件的费用,而且还能够提高服务器的安全性。
之前我们介绍了如何在openSUSE 121下搭建Web服务器,里面详细介绍了在openSUSE 121下搭建服务器的方法,其实除了Red Hat和openSUSE,CentOS也是人们经常用到的搭建Web服务器的Linux版本。
0条评论