使用Shell脚本实现以下需求:
1、创建本地软件仓库
2、安装httpd和bind软件
3、按如下要求生成web配置文件
1、 documentroot /www
2、 listen 8080
3、 welcome index.html
4、访问地址为 www.exam.com:8080
5、放行防火墙规则和定义selinux上下文,使web服务可以正常使用
6、定义dns服务可以正常解析所有需要的主机名
7、所有都ok,echo "all ok"
#!/bin/bash
# 1. 创建本地软件仓库
# 2. 安装httpd和bind软件
yum install -y httpd bind
# 3. 生成web配置文件
cat > /etc/httpd/conf/httpd.conf <<EOL
ServerRoot "/etc/httpd"
Listen 8080
Include conf.modules.d/*.conf
User apache
Group apache
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/www"
<Directory "/www">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
EOL
# 4. 访问地址为 www.exam.com:8080
echo "127.0.0.1 www.exam.com" >> /etc/hosts
# 5. 放行防火墙规则和定义selinux上下文,使web服务可以正常使用
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
setsebool -P httpd_can_network_connect 1
# 6. 定义dns服务可以正常解析所有需要的主机名
cat > /etc/named.conf <<EOL
options {
directory "/var/named";
};
zone "exam.com" IN {
type master;
file "exam.com.zone";
};
EOL
cat > /var/named/exam.com.zone <<EOL
\$TTL 86400
@ IN SOA exam.com. root.exam.com. (
2023100101 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ; Minimum TTL
)
@ IN NS ns.exam.com.
ns IN A 127.0.0.1
www IN A 127.0.0.1
EOL
# 7. 所有都ok,echo "all ok"
echo "all ok"