代码如下,但只能在完全没有安装过的上面运行。安装过的因为其中没有写逻辑判断语句,所以会出现问题。
需要自己配置ip和dns
#!/bin/bash
yum install httpd -y
yum install bind -y
systemctl stop firewalld
setenforce 0
#配置DNS
n1=`sed -n '/listen-on port/=' /etc/named.conf`
sed -i "${n1}d" /etc/named.conf
n1=$((n1 - 1))
echo " listen-on port 53 { any; };" > /root/temp_line.txt
sed -i "${n1}r /root/temp_line.txt" /etc/named.conf
n1=`sed -n '/allow-query/=' /etc/named.conf`
sed -i "${n1}d" /etc/named.conf
n1=$((n1 - 1))
echo " allow-query { any; };" > /root/temp_line.txt
sed -i "${n1}r /root/temp_line.txt" /etc/named.conf
n1=`sed -n '/zone "localhost" IN/=' /etc/named.rfc1912.zones`
n1=$((n1 + 4))
cat << EOF > /root/temp_line.txt
zone "hr.com." IN {
type master;
file "hr.com.zone";
allow-update { none; };
};
zone "test.com." IN {
type master;
file "test.com.zone";
allow-update { none; };
};
EOF
sed -i "${n1}r /root/temp_line.txt" /etc/named.rfc1912.zones
cd /var/named
echo '$TTL 1D' > hr.com.zone
echo '$TTL 1D' > test.com.zone
cat << EOF >> hr.com.zone
@ IN SOA hr.com. root.hr.com (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS www.hr.com.
www A 192.168.153.131
EOF
cat << EOF >> test.com.zone
@ IN SOA test.com. root.test.com (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS www.test.com.
www A 192.168.153.131
EOF
chown named:named hr.com.zone
chown named:named test.com.zone
systemctl start named
#配置apache服务
cd /etc/httpd/conf
echo "Include conf/vhost/*.conf" >> httpd.conf
mkdir vhost
cd vhost
touch hr.conf
cat << YYYY > hr.conf
<VirtualHost 192.168.153.131>
DocumentRoot /var/www/html/hr
ServerName www.hr.com
<Directory "/var/www/html/hr">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
YYYY
touch test.conf
cat << TTTT > test.conf
<VirtualHost 192.168.153.131>
DocumentRoot /var/www/html/test
ServerName www.test.com
<Directory "/var/www/html/test">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
TTTT
cd /var/www/html
mkdir -p hr test
echo "test" > ./test/index.html
echo "hr" > ./hr/index.html
systemctl start httpd
rm -rf /root/temp_line.txt