编译安装httpd
实验准备:
httpd包:httpd-2.4.41.tar.gz
apr依赖包:apr-1.7.0.tar.bz2、apr-util-1.6.1.tar.bz2
开始编译:
下载相关依赖包
[ root@centos7 ~] $yum -y install gcc make pcre-devel openssl-devel expat-devel
解压包
[ root@centos7 src] $ll
total 10324
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
[ root@centos7 src] $tar xvf apr-1.7.0.tar.bz2
[ root@centos7 src] $tar xvf apr-util-1.6.1.tar.bz2
[ root@centos7 src] $tar xvf httpd-2.4.41.tar.gz
[ root@centos7 src] $ll
total 10336
drwxr-xr-x 27 1001 1001 4096 Apr 2 2019 apr-1.7.0
-rw-r--r-- 1 root root 872238 May 14 2019 apr-1.7.0.tar.bz2
drwxr-xr-x 20 1001 1001 4096 Oct 18 2017 apr-util-1.6.1
-rw-r--r-- 1 root root 428595 May 14 2019 apr-util-1.6.1.tar.bz2
drwxr-sr-x 11 root 40 4096 Aug 9 21:36 httpd-2.4.41
-rw-r--r-- 1 root root 9267917 Oct 8 15:10 httpd-2.4.41.tar.gz
三个目录合并编译
[ root@centos7 src] $mv apr-1.7.0 httpd-2.4.41/srclib/apr
[ root@centos7 src] $mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util
[ root@centos7 src] $ll httpd-2.4.41/srclib/
total 12
drwxr-xr-x 27 1001 1001 4096 Dec 10 20:26 apr
drwxr-xr-x 20 1001 1001 4096 Oct 18 2017 apr-util
-rw-r--r-- 1 root 40 121 Feb 11 2005 Makefile.in
进入目录开始编译
[ root@centos7 src] $cd httpd-2.4.41/
[ root@centos7 httpd-2.4.41] $./configure \
--prefix= /app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules= most \
--enable-mpms-shared= all \
--with-mpm= prefork
[ root@centos7 ~] $make && make install
添加PATH变量
[ root@centos7 httpd-2.4.41] $echo 'PATH=/app/httpd24/bin:$PATH ' > /etc/profile.d/httpd24.sh
[ root@centos7 httpd-2.4.41] $. /etc/profile.d/httpd24.sh
启动服务
[ root@centos7 ~] $apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::c970:4699:c2c3:ec08%eth0. Set the ' ServerName' directive globally to suppress this message
[ root@centos7 ~] $ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
创建服务用户
[ root@centos7 ~] $useradd -s /sbin/nologin -r apache
更改为开机启动
[ root@centos7 ~] $vim /etc/rc.d/rc.local
/app/httpd24/bin/apachectl start
[ root@centos7 ~] $ll /etc/rc.d/rc.local
-rw-r--r-- 1 root root 506 Dec 10 20:47 /etc/rc.d/rc.local
[ root@centos7 ~] $chmod +x /etc/rc.d/rc.local
[ root@centos7 ~] $ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 506 Dec 10 20:47 /etc/rc.d/rc.local
指定运行httpd的用户
[ root@centos7 ~] $vim /app/httpd24/conf/httpd.conf
User apache
Group apache
配置帮助
[ root@centos7 ~] $vim /etc/man_db.conf
MANDATORY_MANPATH /app/httpd24/man
重启服务 (这个提示是没有绑定SeeverName)
[ root@centos7 ~] $apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::c970:4699:c2c3:ec08%eth0. Set the ' ServerName' directive globally to suppress this message
指定服务器名
ServerName localhost:80
重启服务
[ root@centos7 ~] $apachectl restart
[ root@centos7 ~] $apachectl restart
[ root@centos7 ~] $apachectl restart
创建service unit文件(使这个服务受system监控)
[ root@centos7 ~] $vim /usr/lib/systemd/system/httpd.service
[ Unit]
Description= The Apache HTTP Server
After= network.target remote-fs.target nss-lookup.target
Documentation= man:httpd( 8)
Documentation= man:apachectl( 8)
[ Service]
Type= forking
ExecStart= /app/httpd24/bin/httpd $OPTIONS -k start
ExecReload= /app/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop= /bin/kill -WINCH { MAINPID}
KillSignal= SIGCONT
PrivateTmp= true
[ Install]
WantedBy= multi-user.target
[ root@centos6 ~] $cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
[ root@centos6 ~] $vim /etc/rc.d/init.d/httpd24
apachectl= /app/httpd24/bin/apachectl
httpd= ${HTTPD-/app/httpd24/bin/httpd}
pidfile= ${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile= ${LOCKFILE-/var/lock/subsys/httpd24}
[ root@centos6 ~] $chkconfig –add httpd24
[ root@centos6 ~] $chkconfig –list httpd24
使用systemd和service启动服务
[ root@centos7 ~] $apachectl stop
[ root@centos7 ~] $systemctl start httpd
[ root@centos7 ~] $ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[ root@centos6 ~] $apachectl stop
[ root@centos6 ~] $service httpd start
重新加载服务
[ root@centos7 ~] $systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded ( /usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled
Active: active ( running) since Tue 2019-12-10 22:06:02 CST; 10s ago
Docs: man:httpd( 8)
man:apachectl( 8)
Process: 7629 ExecStop= /bin/kill -WINCH { MAINPID} ( code= exited, status= 1/FAILURE)
Process: 7747 ExecStart= /app/httpd24/bin/httpd $OPTIONS -k start ( code= exited, status= 0/S
Main PID: 7748 ( httpd)
CGroup: /system.slice/httpd.service
├─7748 /app/httpd24/bin/httpd -k start
├─7749 /app/httpd24/bin/httpd -k start
├─7750 /app/httpd24/bin/httpd -k start
├─7751 /app/httpd24/bin/httpd -k start
├─7752 /app/httpd24/bin/httpd -k start
└─7753 /app/httpd24/bin/httpd -k start
Dec 10 22:06:02 centos7 systemd[ 1] : Starting The Apache HTTP Server.. .
Dec 10 22:06:02 centos7 systemd[ 1] : Started The Apache HTTP Server.
[ root@centos7 ~] $systemctl restart httpd
Warning: httpd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
^C
[ root@centos7 ~] $systemctl daemon-reload
systemctl daemon-reload
重新加载某个服务的配置文件,如果新安装了一个服务,归属于 systemctl 管理,要是新服务的服务程序配置文件生效,需重新加载