1、简述DNS服务器原理,并搭建主-辅服务器。
DNS:Domain Name System 域名系统,应用层协议,是互联网的一项服务。它作为将域名和IP地址相互映射的一个分布式数据库,能够使人更方便地访问互联网基于C/S架构,服务器端:53/udp, 53/tcp
客服端访问一个FQDN,并将该请求发送给本地的域名服务器,当本地的域名服务器收到请求后,就先查询本地的缓存,如果有该纪录项,则本地的域名服务器就直接把查询的结果返回。如果本地的缓存中没有该纪录,则本地域名服务器就直接把请求发给根域名服务器,然后根域名服务器再返回给本地域名服务器一个所查询域(根的子域) 的主域名服务器的地址。本地服务器再向上一步返回的域名服务器发送请求,然后接受请求的服务器查询自己的缓存,如果没有该纪录,则返回相关的下级的域名服务器的地址。以此类推直到找到正确的纪录。本地域名服务器把返回的结果保存到缓存,以备下一次使用,同时还将结果返回给客户机。
#搭建主DNS(IP 10.0.0.38)
yum install bind bind-utils -y # bind-ulits 是依赖包
systemctl start named
#编写配置文件
[root@C8-38-DNS-Server~]#sed -n ‘10,20p‘ /etc/named.conf
options {
// listen-on port 53 { localhost; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
// allow-query { localhost; };
allow-transfer { 10.0.0.98; };
#添加区域
[root@C8-38-DNS-Server~]#sed -n ‘46,49p‘ /etc/named.rfc1912.zones
zone "magedu.org" IN {
type master;
file "magedu.org.zone";
};
#编写文件,且将从服务器10.0.0.98 的NS 和A 记录写入
[root@C8-38-DNS-Server~]#vim /var/named/magedu.org.zone
$TTL 1D
@ IN SOA ns1 admin.magedu.org. (
20210711
1D
1H
1W
3H )
NS ns1
NS ns2
sh NS ns3
ns1 A 10.0.0.38
ns2 A 10.0.0.98
ns3 A 10.0.0.128
www CNAME websrv
websrv A 10.0.0.78
websrv A 10.0.0.88
* A 10.0.0.78
@ A 10.0.0.88
@ MX 10 mailsrv
@ MX 20 mailsrv2
mailsrv A 10.0.0.78
mailsrv2 A 10.0.0.88
#从服务器的搭建
[root@C8-98-slave-DNS ~]# rpm -q bind
bind-9.11.26-4.el8_4.x86_64
[root@C8-98-slave-DNS ~]# rpm -q bind-utils
bind-utils-9.11.26-4.el8_4.x86_64
[root@C8-98-slave-DNS ~]# systemctl disable --now firewalld
[root@C8-98-slave-DNS ~]# systemctl enable --now named
[root@C8-98-slave-DNS ~]# grep -A 6 ‘magedu.org‘ /etc/named.rfc1912.zones
zone "magedu.org" IN {
type slave;
masters {10.0.0.38;};
file "slave/magedu.org.zone.slave";
};
#修改配置文件
[root@C8-98-slave-DNS ~]# grep -A 10 ‘^options‘ /etc/named.conf
options {
// listen-on port 53 { 127.0.0.1; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
// allow-query { localhost; };
allow-transfer { none; };
#从服务器自动获取数据库文件
[root@C8-98-slave-DNS named]# ls /var/named/slaves/
magedu.org.zone.slave
[root@C8-89-slave-DNS named]# \rm /var/named/slaves/magedu.org.zone.slave
[root@C8-98-slave-DNS named]# rndc reload
server reload successful
[root@C8-98-slave-DNS named]# ls /var/named/slaves/
[root@C8-98-slave-DNS named]# ls /var/named/slaves/
[root@C8-98-slave-DNS named]# systemctl restart named
[root@C8-98-slave-DNS named]# ls /var/named/slaves/
magedu.org.zone.slave
[root@C8-98-slave-DNS named]#
#客服端用从DNS服务器来测试
[root@c7-117-dns-client ~]# dig www.magedu.org @10.0.0.98
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.5 <<>> www.magedu.org @10.0.0.98
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6207
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;www.magedu.org. IN A
;; ANSWER SECTION:
www.magedu.org. 86400 IN CNAME websrv.magedu.org.
websrv.magedu.org. 86400 IN A 10.0.0.78
websrv.magedu.org. 86400 IN A 10.0.0.88
;; AUTHORITY SECTION:
magedu.org. 86400 IN NS ns1.magedu.org.
;; ADDITIONAL SECTION:
ns1.magedu.org. 86400 IN A 10.0.0.38
;; Query time: 0 msec
;; SERVER: 10.0.0.98#53(10.0.0.98)
;; WHEN: Sun Jul 11 17:20:30 CST 2021
;; MSG SIZE rcvd: 130
2、搭建并实现智能DNS。
需要五台主机
DNS主服务器和web服务器1:192.168.8.8/24,172.16.0.8/16
web服务器2:192.168.8.7/24
web服务器3:172.16.0.7/16
DNS客户端1:192.168.8.6/24
DNS客户端2:172.16.0.6/16
#配置两个IP地址
#eth0:192.168.8.8/24
#eth1: 172.16.0.8/16
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group
default qlen 1000
? link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
? inet 127.0.0.1/8 scope host lo
? ? ? valid_lft forever preferred_lft forever
? inet6 ::1/128 scope host
? ? ? valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group
default qlen 1000
? link/ether 00:0c:29:f9:8d:90 brd ff:ff:ff:ff:ff:ff
? inet 192.168.8.8/24 brd 192.168.8.255 scope global noprefixroute eth0
? ? ? valid_lft forever preferred_lft forever
? inet6 fe80::20c:29ff:fef9:8d90/64 scope link
? ? ? valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group
default qlen 1000
? link/ether 00:0c:29:f9:8d:11 brd ff:ff:ff:ff:ff:ff
? inet 172.16.0.8/16 brd 172.16.0.255 scope global noprefixroute eth1
? ? ? valid_lft forever preferred_lft forever
? inet6 fe80::20c:29ff:fe11:8d90/64 scope link
? ? ? valid_lft forever preferred_lft forever
? ? ?
?
# 主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 ?
#客户端测试
#分别在三台主机*问
#DNS客户端1:192.168.8.6/24 实现,确保DNS指向192.168.8.8
curl www.magedu.org
www.magedu.org in Beijing
#DNS客户端2:172.16.0.6/16 实现,确保DNS指向172.16.0.8
curl www.magedu.org
www.magedu.org in Shanghai
#DNS客户端3:192.168.8.8 实现,,确保DNS指向127.0.0.1
curl www.magedu.org
www.magedu.org in Other
3、通过编译、二进制安装MySQL5.7多实例
yum install mariadb-server
Systemctl start mariadb
mkdir ?-pv /mysql/{3306,3307,3308}/{data,etc,socket,log,bin,pid}
chown ?-R mysql.mysql /mysql
mysql_install_db ?--datadir=/mysql/3306/data --user=mysql
mysql_install_db ?--datadir=/mysql/3307/data --user=mysql
mysql_install_db ?--datadir=/mysql/3308/data --user=mysql
cp /etc/my.cnf /mysql/3306/etc/
vim /mysql/3306/etc/my.cnf
[mysqld]
#加此行,如果port是3306可省略此行
port=3306 ?
datadir=/mysql/3306/data/
socket=/mysql/3306/socket/mysql.sock
[mysqld_safe]
log-error=/mysql/3306/log/mariadb.log
pid-file=/mysql/3306/pid/mariadb.pid
#重复上面步骤设置3307,3308
?
vim /mysql/3306/bin/mysqld
#!/bin/bash
port=3306
mysql_user="root"
mysql_pwd="magedu"
cmd_path="/usr/bin"
mysql_basedir="/mysql"
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"
function_start_mysql()
{
? ?if [ ! -e "$mysql_sock" ];then
? ? printf "Starting MySQL...\n"
? ? ?${cmd_path}/mysqld_safe --defaultsfile=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
? ?else
? ? printf "MySQL is running...\n"
? ?
? ?
? ? ? ? ?exit
? ?fi
}
function_stop_mysql()
{
? ?if [ ! -e "$mysql_sock" ];then
? ? ? printf "MySQL is stopped...\n"
? ? ? exit
? ?else
? ? ? printf "Stoping MySQL...\n"
? ? ? ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock}
shutdown
? fi
}
function_restart_mysql()
{
? printf "Restarting MySQL...\n"
? function_stop_mysql
? ?sleep 2
? function_start_mysql
}
case $1 in
start)
? function_start_mysql
;;
stop)
? function_stop_mysql
;;
restart)
? function_restart_mysql
;;
*)
? printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
esac
#重复上述过程,分别建立3307,3308的启动脚本
/mysql/3306/bin/mysqld ?start
/mysql/3307/bin/mysqld ?start
/mysql/3308/bin/mysqld ?start
/mysql/3306/bin/mysqld ?start
mysql -uroot -S /mysql/3306/socket/mysql.sock
mariadb>show variables like ‘port’ ?#确认连接的端口
mysqladmin -uroot -S /mysql/3306/socket/mysql.sock password ‘magedu‘ ?#加上新口令
#或者登录mysql,执行下面也可以
Mariadb>update mysql.user set password=password(“centos”) where user=’root’;
Mariadb>flush privileges;
#重复步骤,分别修改别外两个实例3307,3308对应root口令
#测试
mysql -uroot -S /mysql/3306/socket/mysql.sock –p #提示输入口令才能登录
4、整理MySQL数据类型
数值型:
整数 小数
字符型:
变长 定长
日期时间型