1、简述DNS服务器原理,并搭建主-辅服务器。
DNS服务器原理:用户访问指定域名时,先查看本机dns缓存看是否存在域名对应的ip地址,没有的话向DNS服务器发起请求,如果存在相关记录则直接返回ip地址给用户,没有的话继续发送给系统设置的根域名服务器,根域名服务器再按照域名的信息,把请求转发给相关的一级,二级等域名服务器,直到找到用户需要的域名对应的IP地址,再把找到的ip地址,再从原路一级一级返回到用户机,用户通过获取到的ip地址进行访问。
#安装bind
[root@centos8 ~]# yum install bind -y
#主DNS服务器
[root@centos8 ~]# vim /etc/named.conf
#注释掉下面两行
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
#只允许从服务器进行区域传输
allow-transfer { 10.0.0.18;};
[root@centos8 ~]# vim /etc/named.rfc1912.zones
#添加这段
zone "yyang.org" IN {
type master;
file "yyang.org.zone";
};
[root@centos8 ~]# vim /var/named/yyang.org.zone
$TTL 1D
@ IN SOA master admin.yyang.org. ( 1 1D 1H 1W 3D )
NS master
NS slave
master A 10.0.0.8
slave A 10.0.0.18
www IN CNAME websrv
websrv IN A 10.0.0.8
websrv IN A 10.0.0.18
[root@centos8 ~]# chgrp named /var/named/yyang.org.zone
[root@centos8 ~]# systemctl start named
[root@centos8 ~]# rndc reload
#从DNS服务器
[root@centos8 ~]# yum install bind -y
[root@centos8 ~]# vim /etc/named.conf
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
#不允许其它主机进行区域传输
allow-transfer { none;};
[root@centos8 ~]# vim /etc/named.rfc1912.zones
zone "yyang.org" {
type slave;
masters { 10.0.0.8;};
file "slaves/yyang.org.slave";
};
[root@centos8 ~]# systemctl start named
[root@centos8 ~]# rndc reload
server reload successful
[root@centos8 ~]# ls /var/named/slaves/
yyang.org.slave
2、搭建并实现智能DNS。
#主DNS服务端配置文件实现view
yum install bind -y
vim /etc/named.conf
#在文件最前面加下面行
acl beijingnet {
192.168.8.0/24;
};
acl shanghainet {
172.16.0.0/16;
};
acl othernet {
any;
};
#注释掉下面两行
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
# 创建view
view beijingview {
match-clients { beijingnet;};
include "/etc/named.rfc1912.zones.bj";
};
view shanghaiview {
match-clients { shanghainet;};
include "/etc/named.rfc1912.zones.sh";
};
view otherview {
match-clients { othernet;};
include "/etc/named.rfc1912.zones.other";
};
include "/etc/named.root.key";
#实现区域配置文件
vim /etc/named.rfc1912.zones.bj
zone "." IN {
type hint;
file "named.ca";
};
zone "magedu.org" {
type master;
file "magedu.org.zone.bj";
};
vim /etc/named.rfc1912.zones.sh
zone "." IN {
type hint;
file "named.ca";
};
zone "magedu.org" {
type master;
file "magedu.org.zone.sh";
};
vim /etc/named.rfc1912.zones.other
zone "." IN {
type hint;
file "named.ca";
};
zone "magedu.org" {
type master;
file "magedu.org.zone.other";
};
chgrp named /etc/named.rfc1912.zones.bj
chgrp named /etc/named.rfc1912.zones.sh
chgrp named /etc/named.rfc1912.zones.other
# 创建区域数据库文件
vim /var/named/magedu.org.zone.bj
$TTL 1D
@ IN SOA master admin.magedu.org. (
2019042214 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
master A 192.168.8.8
websrv A 192.168.8.7
www CNAME websrv
vim /var/named/magedu.org.zone.sh
$TTL 1D
@ IN SOA master admin.magedu.org. (
2019042214 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
master A 192.168.8.8
websrv A 172.16.0.7
www CNAME websrv
vim /var/named/magedu.org.zone.other
$TTL 1D
@ IN SOA master admin.magedu.org. (
2019042214 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
master A 192.168.8.8
websrv A 127.0.0.1
www CNAME websrv
chgrp named /var/named/magedu.org.zone.bj
chgrp named /var/named/magedu.org.zone.sh
chgrp named /var/named/magedu.org.zone.other
systemctl start named #第一次启动服务
rndc reload #不是第一次启动服务
#实现位于不同区域的三个WEB服务器
#分别在三台主机上安装http服务
#在web服务器1:192.168.8.8/24实现
yum install httpd
echo www.magedu.org in Other > /var/www/html/index.html
systemctl start httpd
#在web服务器2:192.168.8.7/16
echo www.magedu.org in Beijing > /var/www/html/index.html
systemctl start httpd
#在web服务器3:172.16.0.7/16
yum install httpd
echo www.magedu.org in Shanghai > /var/www/html/index.html
systemctl start httpd
3、通过编译、二进制安装MySQL5.7
脚本二进制安装5.7.31
#!/bin/bash
#
#*****************************************************************************
. /etc/init.d/functions
MYSQL=mysql-5.7.31-linux-glibc2.12-x86_64
DATADIR=/data/mysql
MYSQL_ROOT_PASSWORD=yyang
COLOR='\E[1;31m'
END='\E[0m'
check (){
if [ $UID -ne 0 ];then
action "当前用户不是ROOT账号,安装失败" false
exit 1;
fi
if [ -d /data/mysql ];then
action "数据库已经存在" false
else
return
fi
}
install_mysql (){
echo -e "$COLOR开始安装SQL..........$END"
yum -y -q install libaio ncurses-c++-libs ncurses-compat-libs
tar zxf $MYSQL.tar.gz -C /usr/local
cd /usr/local
ln -s $MYSQL mysql
chown -R root.root mysql/
groupadd -r -g 306 mysql
useradd -r -g 306 -u 306 -d $DATADIR -s /sbin/nologin mysql
mkdir $DATADIR -p
chown -R mysql.mysql $DATADIR
cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
mysqld --initialize --user=mysql --datadir=$DATADIR &> /dev/null
awk '/A temporary password/{print $NF}' $DATADIR/mysql.log > ~/tmp.log
cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chown root.mysql /etc/init.d/mysqld
echo "/etc/init.d/mysqld start" >> /etc/rc.local
chmod +x /etc/rc.local
# chkconfig --add mysqld
# chkconfig mysqld on
service mysqld start
if [ $? -ne 0 ];then
action "SQL 安装失败,退出" false
exit 100
else
action "SQL 安装成功" true
fi
MYSQL_OLDPASSWORD=`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log`
mysqladmin -uroot -p$MYSQL_OLDPASSWORD password $MYSQL_ROOT_PASSWORD &>/dev/null
}
check
install_mysql
#源码编译安装
#安装相关依赖包
yum -y install bison bison-devel zlib-devel libcurl-devel libarchive-devel
boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
#做准备用户和数据目录
useradd -r -s /sbin/nologin -d /data/mysql mysql
#准备数据库目录
mkdir /data/mysql
chown mysql.mysql /data/mysql
#下载并解压缩源码包
tar xvf mysql-5.7.31-linux-glibc2.12-x86_64
cd mysql-5.7.31/
cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
#准备环境变量
echo 'PATH=/app/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
#生成数据库文件
cd /app/mysql/
scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
#准备配置文件
cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf
# 准备启动脚本,并启动服务
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
#安全初始化
mysql_secure_installation