Linux云计算架构-源码安装最新版apache2.4.46

Linux云计算架构-源码安装最新版apache2.4.46

1. 解决环境依赖

# 解决环境依赖
[root@server ~]# yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel libtool libtool-ltdl

# 安装依赖包apr、apr-util、pcre
# 版本如下:
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
pcre-8.41.tar.gz
# 解压
[root@server ~]# cd /usr/local/src/
[root@server src]# tar xzf apr-1.6.2.tar.gz
[root@server src]# tar xzf apr-util-1.6.0.tar.gz
[root@server src]# tar xzf pcre-8.41.tar.gz

# 编译安装apr
[root@server src]# cd apr-1.6.2/
[root@server apr-1.6.2]# ./configure --prefix=/usr/local/apr
# 报错:cannot remove 'libtoolT': No such file or directory
# 注释文件configure中的以下行
30951     # $RM "$cfgfile"
[root@server apr-1.6.2]# make -j 4 && make install

# 编译安装apr-util
[root@server apr-1.6.2]# cd ../apr-util-1.6.0/
[root@server apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@server apr-util-1.6.0]# make -j 4 && make install

# 编译安装pcre
[root@server apr-util-1.6.0]# cd ../pcre-8.41/
[root@server pcre-8.41]# ./configure --prefix=/usr/local/pcre
[root@server pcre-8.41]# make -j 4 && make install

# 可以在/usr/local目录下查看相关目录,看是否存在。

2. 源码编译apache

# 安装httpd2.4.46
[root@server ~]# cd /usr/local/src/
[root@server src]# ll httpd-2.4.46.tar.gz
-rw-r--r--. 1 root root 9363314 8月  24 14:20 httpd-2.4.46.tar.gz
[root@server src]# tar xzf httpd-2.4.46.tar.gz
[root@server src]# cd httpd-2.4.46/
[root@server httpd-2.4.46]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=event
[root@server httpd-2.4.46]# make -j 4 && make install

3. 检查apache并设置开机自启

# 查看httpd配置文件
[root@server ~]# ll /usr/local/apache/conf/httpd.conf
-rw-r--r--. 1 root root 18597 8月  24 17:09 /usr/local/apache/conf/httpd.conf

# 查看httpd网站根目录
[root@server ~]# ls /usr/local/apache/htdocs/
index.html

# 生成启动脚本,即是把启动程序放到/etc/init.d/目录下
[root@server ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/
[root@server ~]# chmod +x /etc/init.d/apachectl

# Apache系统服务脚本,权限为754,以便使用systemctl命令管理服务
[root@server ~]# vim /usr/lib/systemd/system/apache.service
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

[root@server ~]# chmod 754 /usr/lib/systemd/system/apache.service

# 启动apache服务,并设置自启动
# 可以看到apache已经正常运行了
[root@server ~]# systemctl start apache.service 
[root@server ~]# systemctl enable apache.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/apache.service to /usr/lib/systemd/system/apache.service.
[root@server ~]# netstat -antup | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      62282/httpd         
udp        0      0 0.0.0.0:48010           0.0.0.0:*                           6202/avahi-daemon:  
[root@server ~]# ps aux | grep apache
root      62282  0.0  0.2  99468  2576 ?        Ss   17:23   0:00 /usr/local/apache/bin/httpd -k start
daemon    62343  0.0  0.2 388380  2364 ?        Sl   17:24   0:00 /usr/local/apache/bin/httpd -k start
daemon    62344  0.0  0.2 388380  2364 ?        Sl   17:24   0:00 /usr/local/apache/bin/httpd -k start
daemon    62345  0.0  0.2 388380  2368 ?        Sl   17:24   0:00 /usr/local/apache/bin/httpd -k start
root      62464  0.0  0.0 112724   984 pts/0    S+   17:25   0:00 grep --color=auto apache

# 在这里创建一个apache用户,用来运行apache服务
[root@server ~]# useradd -M -s /sbin/nologin apache
[root@server ~]# vim /usr/local/apache/conf/httpd.conf 
166 User apache
167 Group apache

# 修改源码包安装位置的用户权限,所有者和所属组为apache
[root@server ~]# chown -R apache:apache /usr/local/apache/

# 重启apache服务,可以看到运行apache的用户已经改为了apache
[root@server ~]# systemctl restart apache.service 
[root@server ~]# ps aux | grep apache
root      62640  0.0  0.2  99468  2576 ?        Ss   17:32   0:00 /usr/local/apache/bin/httpd -k start
apache    62679  0.0  0.2 388380  2372 ?        Sl   17:33   0:00 /usr/local/apache/bin/httpd -k start
apache    62680  0.0  0.2 388380  2372 ?        Sl   17:33   0:00 /usr/local/apache/bin/httpd -k start
apache    62681  0.0  0.2 388380  2372 ?        Sl   17:33   0:00 /usr/local/apache/bin/httpd -k start
root      62773  0.0  0.0 112724   984 pts/0    S+   17:33   0:00 grep --color=auto apache

# 开放80端口号,可以看到已经开放了
[root@server ~]# firewall-cmd --list-port
80/tcp

# 输入网址:http://192.168.10.10/
# 如下图则表示已经安装成功了。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_36522099/article/details/108204088