apache服务器安装(如何配置Apache服务器)
大家好,今天小编来为大家解答以下的问题,关于apache服务器安装,如何配置Apache服务器这个很多人还不知道,现在让我们一起来看看吧!
Centos 下Apache(httpd) 安装过程
其实,网上这块的部署文章非常多。随便搜索,都有。
这篇文章,老徐帮大家挑选几个比较重点的过程&命令。
1.有些 linux版本中已经预置了有Apache,并且已经是服务了,所有首先检查系统中是否已经存在httpd的服务
1)先检查服务器上是否已经启动了此服务。
命令如下
ps-ef|grep httpd
2)查看linux系统服务中有没有httpd
chkconfig--list| grep httpd
3)如果有服务存在,那么需要先关闭httpd服务自启动
命令 chkconfig httpd off
4)停止httpd服务
命令 service httpd stop
5)再次查看,是否有进程存在
命令 ps-ef|grep httpd
6)如果有进程存在,关闭进程
命令 kill-9 pid
1)先检查安装包的名字
命令 rpm-qa|grep httpd
<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas,"Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;-webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@istester]~# rpm-qa|grep httpd
httpd-2.2.15-69.el6.centos.x86_64
httpd-tools-2.2.15-69.el6.centos.x86_64</pre>
2)根据安装包名字删除包
rpm-e httpd-tools-2.2.15-69.el6.centos.x86_64
rpm-e httpd-2.2.15-69.el6.centos.x86_64
3)删除httpd.conf文件
<pre class="prettyprint" style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas,"Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;-webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">#先检查文件在哪
find/-name httpd.conf
rm/xxx/xxx/httpd.conf</pre>
3.准备事项已完成,剩下的就是常规安装了。
注:我们通过yum的方式,在线安装,非常简单。
1)检查是否存在httpd包
<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas,"Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;-webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[www@istester~]$ yum list httpd
Loaded plugins: security
base| 3.7 kB 00:00
epel| 4.7 kB 00:00
epel/primary_db| 6.0 MB 00:00
extras| 3.4 kB 00:00
extras/primary_db| 28 kB 00:00
updates| 3.4 kB 00:00
updates/primary_db| 3.2 MB 00:00
Available Packages
httpd.x86_64 2.2.15-69.el6.centos base</pre>
2、安装Apache
yum install httpd
<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas,"Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;-webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Total 20 MB/s| 932 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: apr-util-ldap-1.3.9-3.el6_0.1.x86_64 1/4
Updating: httpd-tools-2.2.15-69.el6.centos.x86_64 2/4
Installing: httpd-2.2.15-69.el6.centos.x86_64 3/4
Cleanup: httpd-tools-2.2.15-53.el6.centos.x86_64 4/4
Verifying: httpd-tools-2.2.15-69.el6.centos.x86_64 1/4
Verifying: httpd-2.2.15-69.el6.centos.x86_64 2/4
Verifying: apr-util-ldap-1.3.9-3.el6_0.1.x86_64 3/4
Verifying: httpd-tools-2.2.15-53.el6.centos.x86_64 4/4
Installed:
httpd.x86_64 0:2.2.15-69.el6.centos
Dependency Installed:
apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1
Dependency Updated:
httpd-tools.x86_64 0:2.2.15-69.el6.centos
Complete!</pre>
安装过程,不用理会,如果看到如上提示,说明安装成功了。
3、设置Apache服务的启动级别
chkconfig--levels 235 httpd on
Apache是一个服务,所以,可以通过设置服务的启动级别来让它启动。
4、启动服务
两种方式,
1)如下/etc/init.d/httpd start
2)如下
service httpd start
5、查看服务是否正常启动
两种方式,
1)查看服务状态
<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas,"Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;-webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@istester www]# service httpd status
httpd(pid 10339) is running...</pre>
2)查看进程
<pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas,"Courier New", monospace; font-size: 12px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.38462; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;-webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@istester www]# ps-ef|grep httpd| grep-v grep
root 10339 1 0 23:15? 00:00:00/usr/sbin/httpd
apache 10341 10339 0 23:15? 00:00:00/usr/sbin/httpd
apache 10342 10339 0 23:15? 00:00:00/usr/sbin/httpd
apache 10343 10339 0 23:15? 00:00:00/usr/sbin/httpd
apache 10344 10339 0 23:15? 00:00:00/usr/sbin/httpd
apache 10345 10339 0 23:15? 00:00:00/usr/sbin/httpd
apache 10346 10339 0 23:15? 00:00:00/usr/sbin/httpd
apache 10347 10339 0 23:15? 00:00:00/usr/sbin/httpd
apache 10348 10339 0 23:15? 00:00:00/usr/sbin/httpd</pre>
补充,
1)停止服务
service httpd stop
2)重启服务
service httpd restart
6、安装之后的说明:
1)验证是否安装成功
现在打开 http://ip地址,看看有没有Apache的默认页面出来了?如果有就对了。
2)安装目录说明
Apache默认将网站的根目录指向/var/www/html
默认的主配置文件是/etc/httpd/conf/httpd.conf
配置存储在的/etc/httpd/conf.d/目录
End
文/ IDO老徐
怎样安装和启动Apache服务器
安装和启动Apache服务器,一共5个步骤.
步骤/方法
回到Webmin的服务器管理界面中,点击第一个图标就可以进入Apache服务器的管理界面。在“服务器”图标的下方,有如下子菜单:“模块配置”、“应用修改”、“停止/启动Apache”、“搜索文档”。然后,可以看到整个配置界面分为两个部分,一个是全局配置,一个是虚拟服务器配置。
打开全局配置下的“网络和地址”图标,在“监听地址和端口”选项后,设置服务器的IP地址和https地址,并输入端口,如80、443。当然,用户也可以自己定义或修改端口。设置完毕,单击“保存”按钮。
如果需要增加虚拟服务器,可以通过Apache服务器主界面中的“创建新的虚拟服务器”选项进行设置。首先指定地址和端口,然后单击“根文件”右边的按钮,选择“/var/www/html”,在“服务器名称”中填入地址。设置完毕。
在缺省服务器的下方出现了一个虚拟服务器,旁边的注释说明了服务器的详细情况。点击此虚拟服务器的图标,即可进入其设置界面。除了通过Webmin进行配置外,用户还可以通过RedhatLinux上的设置工具进行修改。打开RedhatLinux中“应用程序”菜单上的“系统设置”菜单,选择“服务器设置”上的“HTTP”,也可以对虚拟主机进行修改,效果是一样的。
单击“编辑”按钮就可以对虚拟主机的属性进行修改了。此外,还可以进行服务器、调整性能等方面的操作。
配置完成后,点“启动Apache”,打开页面即可进行测试。
如何配置Apache服务器
1、如何设置请求等待时间
在httpd.conf里面设置:
TimeOut n
其中n为整数,单位是秒。
设置这个TimeOut适用于三种情况:
2、如何接收一个get请求的总时间
接收一个post和put请求的TCP包之间的时间
TCP包传输中的响应(ack)时间间隔
3、如何使得apache监听在特定的端口
修改httpd.conf里面关于Listen的选项,例如:
Listen 8000
是使apache监听在8000端口
而如果要同时指定监听端口和监听地址,可以使用:
Listen 192.170.2.1:80
Listen 192.170.2.5:8000
这样就使得apache同时监听在192.170.2.1的80端口和192.170.2.5的8000端口。
当然也可以在httpd.conf里面设置:
Port 80
这样来实现类似的效果。
4、如何设置apache的最大空闲进程数
修改httpd.conf,在里面设置:
MaxSpareServers n
其中n是一个整数。这样当空闲进程超过n的时候,apache主进程会杀掉多余的空闲进程而保持空闲进程在n,节省了系统资源。如果在一个apache非常繁忙的站点调节这个参数才是必要的,但是在任何时候把这个参数调到很大都不是一个好主意。
同时也可以设置:
MinSpareServers n
来限制最少空闲进程数目来加快反应速度。
5、apache如何设置启动时的子服务进程个数
在httpd.conf里面设置:
StartServers 5
这样启动apache后就有5个空闲子进程等待接受请求。
也可以参考MinSpareServers和MaxSpareServers设置。
END,本文到此结束,如果可以帮助到大家,还望关注本站哦!