我们经常在linux下使用某个节点node,而浏览器其实和node也是有联系的,这个桥梁就是apache的httpd服务。接下来我们来看具体的使用过程。以node的ip为10.10.37.248为例。
一、判断httpd是否启动
在浏览器上输入ip回车:
再到node上查看并启动进程:
[root@localhost ~]# ps -ef |grep httpd root 20609 20588 0 19:35 pts/0 00:00:00 grep httpd [root@localhost ~]# service httpd start httpd: unrecognized service
所得得知没有httpd服务,所以我们首先要安装httpd服务。
二、安装运行httpd
1. 安装
[root@localhost ~]# yum install httpd
在这个安装过程中下载安装了5个包:Installing : apr-1.3.9-5.el6_2.x86_64 Installing : apr-util-1.3.9-3.el6_0.1.x86_64 Installing : httpd-tools-2.2.15-39.el6.centos.x86_64 Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 Installing : httpd-2.2.15-39.el6.centos.x86_64
2. 然后再次执行httpd的启动:[root@localhost ~]# service httpd start Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName [ OK ] [root@localhost ~]# ps -ef |grep httpd root 20698 1 0 19:39 ? 00:00:00 /usr/sbin/httpd apache 20700 20698 0 19:39 ? 00:00:00 /usr/sbin/httpd apache 20701 20698 0 19:39 ? 00:00:00 /usr/sbin/httpd apache 20702 20698 0 19:39 ? 00:00:00 /usr/sbin/httpd apache 20703 20698 0 19:39 ? 00:00:00 /usr/sbin/httpd apache 20704 20698 0 19:39 ? 00:00:00 /usr/sbin/httpd apache 20705 20698 0 19:39 ? 00:00:00 /usr/sbin/httpd apache 20706 20698 0 19:39 ? 00:00:00 /usr/sbin/httpd apache 20707 20698 0 19:39 ? 00:00:00 /usr/sbin/httpd root 20709 20588 0 19:39 pts/0 00:00:00 grep httpd [root@localhost ~]#
三、测试
1. 此时在浏览器下输入ip回车:
说明服务启动成功。
2. 查看log:[root@localhost html]# cd /var/log/httpd/ [root@localhost httpd]# ls access_log error_log [root@localhost httpd]# cat error_log [Mon Nov 24 19:39:52 2014] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0 [Mon Nov 24 19:39:52 2014] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Mon Nov 24 19:39:52 2014] [notice] Digest: generating secret for digest authentication ... [Mon Nov 24 19:39:52 2014] [notice] Digest: done [Mon Nov 24 19:39:52 2014] [notice] Apache/2.2.15 (Unix) DAV/2 configured -- resuming normal operations [Mon Nov 24 19:40:36 2014] [error] [client 10.10.19.235] Directory index forbidden by Options directive: /var/www/html/ [Mon Nov 24 19:40:36 2014] [error] [client 10.10.19.235] File does not exist: /var/www/html/favicon.ico [root@localhost httpd]#
说明是没有index文件,所以我们创建一个index.html文件:[root@localhost httpd]# echo "hello" > /var/www/html/index.html
3. 再在浏览器上输入ip回车:
说明访问成功。
四、补充说明
1. 访问index有可能出现的问题:
Permission denied: access to /index.html denied。
解决办法:要确定/var/www/html这几级目录都具有可执行权限。如果确定了之后还是permission denied,还可以再试着把index.html删除然后重新创建一个index.html(有可能和浏览器的缓存有关系)。
2. 要查看log:
log可能在一下几个地方:
- 在安装目录下即ServerRoot下有个logs目录,里面有errorlog和accesslog
- 用yum安装的话默认在/etc/httpd下的logs下【这个logs是一个链接文件】
- /var/log/httpd/