标签:防火墙 虚拟主机 下载软件 软连接 apache2.4.25
安装之前准备:
配置好防火墙,selinux,时区.
检查系统是否安装了httpd服务
yum install gcc gcc-c++ zlib-devel
下载软件,pcre,apr,apr-util,apache
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
wget http://apache.fayea.com/httpd/httpd-2.4.25.tar.gz
创建软件安装目录及下载目录
1.下载目录: /opt/dowanload
2.安装目录:
[root@bbs ~]# tree -L 1 /opt/app/ /opt/app/ #主目录 ├── apache -> /opt/app/apache2.4.25 #软连接,方便以后升级及管理 ├── apache2.4.25 #apache安装目录,所有文件存放地 ├── apr #apr 目录 ├── apr-util #apr-util 目录 └── pcre #pcre 目录 |
编译安装依赖包
tar zxf apr apr-util pcre 先安装apr,apr-util依赖apr #cd /opt/download #cd apr-1.5.2 #./configure --prefix=/opt/app/apr #make && make install #cd apr-util-1.5.4 #./configure --prefix=/opt/app/apr-util --with-apr=/opt/app/apr #make && make install #cd pcre-8.40 #./configure --prefix=opt/app/pcre #make && make install |
开始编译安装apache
# tar zxf httpd-2.4.25.tar.gz # cd http-2.4.25 # ./configure --prefix=/opt/app/apache2.4.25 --with-apr=/opt/app/apr --with-apr-util=/opt/app/apr-util --with-pcre=/opt/app/pcre --with-mpm=worker --enable-rewrite --enable-so --enable-headers --enable-expires --enable-deflate # make && make install |
虚拟主机篇(先备份好需要改动的配置文件)
#软连接 ln -s /opt/app/apache2.4.25 /opt/app/apache
默认安装完成后有如下文件: [root@bbs extra]# tree -L 1 /opt/app/apache /opt/app/apache ├── bin #启动目录 ├── build ├── cgi-bin ├── conf ├── error ├── htdocs ├── icons ├── include ├── logs ├── man ├── manual └── modules [root@bbs ~]# tree -L 1 /opt/app/apache/conf/ /opt/app/apache/conf/ ├── extra #此文件存放虚拟主机配置文件等 ├── httpd.conf #主配置文件 ├── magic ├── mime.types └── original |
配置虚拟主机
[root@bbs extra]# tree -L 1 /opt/app/apache/conf/extra /opt/app/apache/conf/extra ├── httpd-autoindex.conf ├── httpd-dav.conf ├── httpd-default.conf ├── httpd-info.conf ├── httpd-languages.conf ├── httpd-manual.conf ├── httpd-mpm.conf ├── httpd-multilang-errordoc.conf ├── httpd-ssl.conf ├── httpd-userdir.conf ├── httpd-vhosts.conf #虚拟主机文件, ├── httpd-vhosts.conf.2017-04-05 └── proxy-html.conf |
编辑虚拟主机文档,跟2.4版本前的稍微有些变动
[root@bbs extra]# egrep -v "^$|#" /opt/app/apache/conf/extra/httpd-vhosts.conf <VirtualHost *:80> ServerAdmin sadoc.blog.51cto.com DocumentRoot "/var/www" #web网站存放目录,请mkdir好目录 ServerName bbs.52cto.com #域名 ServerAlias 52ctt.com #域名别名 ErrorLog "logs/bbs-error_log" #错误日志 CustomLog "logs/bbs-access_log" common #客户端访问日志 </VirtualHost> |
修改主配置文件
DocumentRoot "/opt/app/apache2.4.25/htdocs" <Directory "/opt/app/apache2.4.25/htdocs"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> #新增如下,不增加会报错403错误. <Directory "/var/www"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> #取消了vhost的加载注释 Include conf/extra/httpd-vhosts.conf |
apache服务启动方式:
[root@bbs ~]# /opt/app/apache/bin/apachectl -t #检查配置文件是否正常. Syntax OK [root@bbs ~]# /opt/app/apache/bin/apachectl -k start #启动服务 |
自己手动写启动脚本,方便启动.
脚本写的很简单,也可以用进程数量判断
[root@bbs ~]# cat /etc/init.d/httpd #!/bin/bash #author:http://sadoc.blog.51cto.com/ #2017-04-06 #加载函数库 . /etc/rc.d/init.d/functions #定义变量本脚本以Pid文件是否存在判断启动. PID="/opt/app/apache/logs/httpd.pid" STARTING="/opt/app/apache/bin/apachectl" start(){ if [ ! -s "$PID" ];then $STARTING -k start action "Apache Start" /bin/true fi } stop(){ if [ -s "$PID" ];then $STARTING -k stop action "Apache Stop:" /bin/true fi } case $1 in start) start ;; stop) stop
;; status) status
;;
reload) reload
;;
esac |
# chmod +x /etc/init.d/httpd
用了脚本后,直接yum方式启动,centos7可以用systemctl管理启动
[root@bbs ~]# systemctl status httpd.service ● httpd.service - (null) Loaded: loaded (/etc/rc.d/init.d/httpd; bad; vendor preset: disabled) Active: active (running) since Wed 2017-04-05 17:20:03 CST; 22h ago Docs: man:systemd-sysv-generator(8) Process: 3873 ExecStart=/etc/rc.d/init.d/httpd start (code=exited, status=0/SUCCESS) CGroup: /system.slice/httpd.service ├─3877 /opt/app/apache2.4.25/bin/httpd -k start ├─3879 /opt/app/apache2.4.25/bin/httpd -k start ├─3880 /opt/app/apache2.4.25/bin/httpd -k start ├─3881 /opt/app/apache2.4.25/bin/httpd -k start └─3963 /opt/app/apache2.4.25/bin/httpd -k start Apr 05 17:20:03 bbs.52cto.com systemd[1]: Starting (null)... Apr 05 17:20:03 bbs.52cto.com httpd[3873]: Apache Start [ OK ] Apr 05 17:20:03 bbs.52cto.com systemd[1]: Started (null). |
# 查看服务端口
[root@bbs ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 3877 root 4u IPv6 29554 0t0 TCP *:http (LISTEN)
httpd 3879 daemon 4u IPv6 29554 0t0 TCP *:http (LISTEN)
httpd 3880 daemon 4u IPv6 29554 0t0 TCP *:http (LISTEN)
httpd 3881 daemon 4u IPv6 29554 0t0 TCP *:http (LISTEN)
httpd 3963 daemon 4u IPv6 29554 0t0 TCP *:http (LISTEN)
[root@bbs ~]# ps -ef | grep httpd
root 3877 1 0 Apr05 ? 00:00:03 /opt/app/apache2.4.25/bin/httpd -k start
daemon 3879 3877 0 Apr05 ? 00:00:00 /opt/app/apache2.4.25/bin/httpd -k start
daemon 3880 3877 0 Apr05 ? 00:00:00 /opt/app/apache2.4.25/bin/httpd -k start
daemon 3881 3877 0 Apr05 ? 00:00:00 /opt/app/apache2.4.25/bin/httpd -k start
daemon 3963 3877 0 Apr05 ? 00:00:00 /opt/app/apache2.4.25/bin/httpd -k start
root 6074 2380 0 15:45 pts/0 00:00:00 grep --color=auto httpd
查PID文件
[root@bbs ~]# cat /opt/app/apache/logs/httpd.pid 3877 |
Apache2.4.25编译安装之虚拟主机For Centos7
标签:防火墙 虚拟主机 下载软件 软连接 apache2.4.25
原文地址:http://sadoc.blog.51cto.com/12189157/1913461