小知识:源码安装apache脚本部署过程详解

源码安装apache脚本部署

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
[root@localhost ~]# ls
anaconda-ks.cfg  httpd.tar.xz
[root@localhost ~]# tar xf httpd.tar.xz  解压存放脚本的压缩包
[root@localhost ~]# ls
anaconda-ks.cfg  httpd  httpd.tar.xz
[root@localhost ~]# cd httpd/
[root@localhost httpd]# ls
apache_lnh.sh(编译安装apache脚本)  config.sh(附属脚本)  files
[root@localhost httpd]# ls files/    //存放安装包的目录
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz  httpd-2.4.54.tar.gz  zhuawawa(源码包的目录)
[root@localhost httpd]# cat apache_lnh.sh
#/bin/bash
#列出httpd版本号进行选择
cat > /tmp/xbz.txt <<EOF
请输入要安装的版本序号:
1. 2.4.54
2. 2.4.53
q. 退出
EOF
cat /tmp/xbz.txt
read -p “选择版本号”  apache_version
case $apache_version in
1)
apache_version=$(awk NR==2{print $2}  /tmp/xbz.txt)
echo $apache_version
;;
2)
apache_version=$(awk NR==3{print $2}  /tmp/xbz.txt)
echo $apache_version
;;
q)
apache_version=$(awk NR==4{print $2}  /tmp/xbz.txt)
echo $apache_version
exit
;;
*)
echo “错误输入”
exit
esac
#设置执行权限
if [ $UID -ne 0 ];then
echo “请以管理员用户进行执行”
exit
fi
#定义变量
install_dir=/usr/local/apache
#创建用户
id apache &> /dev/null
if [ $? -ne 0 ];then
useradd -r -M -s /sbin/nologin apache
else
echo “用户已存在”
fi
#安装依赖包
dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget make vim  zip –allowerasing
#解压源码包
rm -rf /tmp/*
tar xf files/apr-1.7.0.tar.gz -C /tmp/
tar xf files/apr-util-1.6.1.tar.gz -C /tmp/
tar xf files/httpd-$apache_version.tar.gz -C /tmp/
#编译安装apr
cd /tmp/apr-1.7.0
if [ ! -d /usr/local/apr ];then
sed -i /$RM “$cfgfile”/d configure
./configure –prefix=/usr/local/apr && \
make && make install   
else
ls /usr/local
echo “apr 编译安装完成”
fi
#编译安装apr-util
cd ../apr-util-1.6.1/
if [ ! -d /usr/local/apr-util ];then
./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr && \
make && make install
else
ls /usr/local/
echo “apr-util 编译安装完成”      
fi
#编译安装httpd
cd ../httpd-$apache_version/
if [ ! -d ${install_dir} ];then
./configure –prefix=${install_dir} \
–enable-so \
–enable-ssl \
–enable-cgi \
–enable-rewrite \
–with-zlib \
–with-pcre \
–with-apr=/usr/local/apr \
–with-apr-util=/usr/local/apr-util/ \
–enable-modules=most \
–enable-mpms-shared=all \
–with-mpm=prefork  
make && make install   
else
ls ${install_dir}
echo “httpd 编译安装完成”
fi
#设置环境变量,man文档,头文件
echo “export PATH=${install_dir}/bin:\$PATH” > /etc/profile.d/apache.sh
ln -s ${install_dir}/include /usr/include/apache &> /dev/null
grep apache /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
sed -i “22a MANDATORY_MANPATH                       ${install_dir}/man” /etc/man_db.conf
fi
#将其加入systemd服务里面
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=httpd server daemon
After=network.target
[Service]
Type=forking
ExecStart=${install_dir}/bin/apachectl start
ExecStop=${install_dir}/bin/apachectl stop
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
EOF
#加载文件并设置开机自启
systemctl daemon-reload
systemctl enable –now httpd
#查看端口
ss -antl
[root@localhost httpd]# cat config.sh
#!/bin/bash
#定义变量
install_dir=$(grep ^install_dir= apache_lnh.sh  | awk -F= {print $2} )
echo $install_dir
#添加包含虚拟主机
grep Include conf/extra/httpd-vhosts.conf $install_dir/conf/httpd.conf &> /dev/null
if [ $? -eq 0 ];then
echo “Include conf/extra/httpd-vhosts.conf” >> $install_dir/conf/httpd.conf
fi
#配置虚拟主机
cat > $install_dir/conf/extra/httpd-vhosts.conf <<EOF
<VirtualHost *:80>
DocumentRoot “$install_dir/htdocs/zhuawawa.example.com”
ServerName zhuawawa.example.com
ErrorLog “logs/zhuawawa.example.com-error_log”
CustomLog “logs/zhuawawa.example.com-access_log” common
</VirtualHost>
EOF
#添加防火墙规则
firewall-cmd –add-rich-rule rule family=ipv4 source address=0.0.0.0/0 port port=80 protocol=tcp accept –permanent &> /dev/null
firewall-cmd –reload
#创建网站存放目录
mkdir -p $install_dir/htdocs/zhuawawa.example.com
cp -r files/zhuawawa/* $install_dir/htdocs/zhuawawa.example.com
#重启httpd
systemctl restart httpd
#查看端口
ss -antl
[root@localhost httpd]# ls
apache_lnh.sh  config.sh  files
[root@localhost httpd]# ls files/
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz  httpd-2.4.54.tar.gz  zhuawawa(提前将源码包解压到这里)
[root@localhost httpd]# ls files/zhuawawa/  (此处是我解压的源码包)
Battle_City  audio  css  images  index.html  js  tk.zip

进行访问:

%小知识:源码安装apache脚本部署过程详解-猿站网-插图

?
1
2
3
[root@localhost ~]# tar -Jcf httpd.tar.xz httpd/  //压缩脚本存放目录
[root@localhost ~]# ls
anaconda-ks.cfg  httpd  httpd.tar.xz

到此这篇关于源码安装apache脚本部署的文章就介绍到这了,更多相关源码安装apache内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.cnblogs.com/tushanbu/archive/2022/09/19/16707212.html

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Zabbix6通过ODBC方式监控Oracle 19C的详细过程

2023-3-5 15:44:21

建站知识

小知识:Apache SkyWalking 监控 MySQL Server 实战解析

2023-3-5 15:51:04

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索