centos7-一键安装网站脚本:dns搭建和配置apache服务

代码如下,但只能在完全没有安装过的上面运行。安装过的因为其中没有写逻辑判断语句,所以会出现问题。
需要自己配置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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值