1、简述DNS服务器原理,并搭建主-辅服务器。
DNS(Domain Name Service的缩写)的作用就是根据域名查出IP地址。IP地址是由32位二进制数字组成,人们很难记住这些IP,相反,大家愿意使用比较容易记忆的主机名字。而电脑在处理IP数据报文时,是使用IP地址的,因为它是固定长度。
DNS查询的类型对于客户端来说是递归查询,对于DNS服务器来说,绝大多数是迭代查询的。DNS名称解析中,从名称到IP的查询叫做正向解析,而从IP到名称的查询叫做反向解析。如果DNS服务器至少解析了一个或一个以上的域叫做DNS主服务器或者DNS辅助服务器,如果不负责任何解析叫做DNS缓存服务器。
现在互联网规模很大,DNS被设计成一个分布式的数据库系统,他分布的功能就是把一个大的数据库切割成很多小的数据库,来分别提供一部分数据的处理。全球一共分布了13台DNS根服务器,名字为A至M。
搭建主从dns
#实验机器
DNS主服务器:10.0.0.7
DNS从服务器:10.0.0.17
web服务器、测试端:10.0.0.8
#前提条件
关闭防火墙、Selinux、时间同步
#实现步骤
1、主DNS配置
[root@Centos7 ~]# dnf install bind -y
vim /etc/named.conf
#注释掉下面两行
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
#加上下面行,只允许从服务器进行区域传输
allow-transfer { 10.0.0.17; };
vim /etc/named.rfc1912.zones
#加上这段
zone "magedu.org" {
type master;
file "magedu.org.zone";
};
#DNS区域数据库文件
cp -p /var/named/named.localhost /var/named/magedu.org.zone
#如果没有-p,需要改权限。chgrp named magedu.org.zone
vim /var/named/magedu.org.zone
$TTL 1D
@ IN SOA master admin.magedu.org. (
1 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
NS slave
master A 10.0.0.7
slave A 10.0.0.17
www A 10.0.0.8
[root@centos7 ~]# named-checkconf
[root@centos7 ~]# named-checkzone magedu.org /var/named/magedu.org.zone
zone magedu.org/IN: loaded serial 1
OK
systemctl start named #第一次启动服务
rndc reload #不是第一次启动服务
2、从服务器
[root@centos7 ~]# yum install bind -y
vim /etc/named.conf
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
#不允许其它主机进行区域传输
allow-transfer { none;};
vim /etc/named.rfc1912.zones
zone "magedu.org" {
type slave;
masters { 10.0.0.7; };
file "slaves/magedu.org.slave";
};
systemctl start named
[root@centos7 slaves]# ll /var/named/slaves/magedu.org.slave
-rw-r--r-- 1 named named 277 Aug 29 18:31 /var/named/slaves/magedu.org.slave
#3、客户端
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=10.0.0.7
DNS2=10.0.0.17
#验证从DNS服务器是否可以查询
[root@localhost ~]# dig www.magedu.org
[root@localhost ~]# curl www.magedu.org
2、搭建并实现智能DNS。
设置服务器双IP
#三台服务器
#192.168.2.173 #服务器
#192.168.2.157 #模拟北京
#129.16.0.7 #模拟上海
[root@localhost ~]# ip a a 129.16.0.8/16 dev ens192 label ens192:1
[root@localhost ~]# 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: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:ac:26:1e brd ff:ff:ff:ff:ff:ff
inet 192.168.2.173/24 brd 192.168.2.255 scope global noprefixroute ens192
valid_lft forever preferred_lft forever
inet 129.16.0.8/16 scope global ens192:1
valid_lft forever preferred_lft forever
inet6 fe80::3b03:7295:36b3:5dad/64 scope link noprefixroute
valid_lft forever preferred_lft forever
设置模拟上海IP
[root@shanghaiclient ~]# ip a a 129.16.0.7/16 dev ens192 label ens192:1
[root@shanghaiclient ~]# 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: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:ac:6c:a2 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.158/24 brd 192.168.2.255 scope global noprefixroute ens192
valid_lft forever preferred_lft forever
inet 129.16.0.7/16 scope global ens192:1
valid_lft forever preferred_lft forever
inet6 fe80::deaf:42f5:93ec:36d0/64 scope link noprefixroute
valid_lft forever preferred_lft forever
服务器安装NDS服务以及相关配置
[root@localhost ~]# yum -y install bind ; systemctl enable --now named
[root@localhost ~]# vim /etc/named.conf
#添加下面内容
acl beijingnet {
192.168.2.0/24;
};
acl shanghainet {
129.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";
实现区域配置文件
[root@localhost ~]# cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bj
[root@localhost ~]# vim /etc/named.rfc1912.zones.bj
#添加下面内容
zone "yezeng.org" IN {
type master;
file "yezeng.org.zone.bj";
};
zone "." IN {
type hint;
file "named.ca";
};
[root@localhost ~]# cp /etc/named.rfc1912.zones.bj /etc/named.rfc1912.zones.sh
[root@localhost ~]# cp /etc/named.rfc1912.zones.bj /etc/named.rfc1912.zones.other
[root@localhost ~]# vim /etc/named.rfc1912.zones.sh
#添加下面内容
zone "yezeng.org" IN {
type master;
file "yezeng.org.zone.sh";
};
zone "." IN {
type hint;
file "named.ca";
};
[root@localhost ~]# vim /etc/named.rfc1912.zones.other
#添加下面内容
zone "yezeng.org" IN {
type master;
file "yezeng.org.zone.other";
};
zone "." IN {
type hint;
file "named.ca";
};
#修改文件权限
[root@localhost named]# chgrp named /etc/named.rfc1912.zones.bj
[root@localhost named]# chgrp named /etc/named.rfc1912.zones.sh
[root@localhost named]# chgrp named /etc/named.rfc1912.zones.other
生成区域数据库文件
[root@localhost ~]# cd /var/named/
[root@localhost named]# vim yezeng.org.zone.bj
$TTL 1D
@ IN SOA ns1 admin ( 1 1D 1H 1W 2H)
NS ns1
ns1 A 192.168.2.173
www A 192.168.2.200
[root@localhost named]# vim yezeng.org.zone.sh
$TTL 1D
@ IN SOA ns1 admin ( 1 1D 1H 1W 2H)
NS ns1
ns1 A 192.168.2.173
www A 129.16.0.200
[root@localhost named]# vim yezeng.org.zone.other
$TTL 1D
@ IN SOA ns1 admin ( 1 1D 1H 1W 2H)
NS ns1
ns1 A 192.168.2.173
www A 127.0.0.1
客户端进行访问测试
#模拟北京
[root@beijingclient ~]# host www.yezeng.org 192.168.2.173
Using domain server:
Name: 192.168.2.173
Address: 192.168.2.173#53
Aliases:
www.yezeng.org has address 192.168.2.200
#模拟上海
[root@shanghaiclient ~]# host www.yezeng.org 129.16.0.8
Using domain server:
Name: 129.16.0.8
Address: 129.16.0.8#53
Aliases:
www.yezeng.org has address 129.16.0.200
#本地访问
[root@localhost named]# host www.yezeng.org 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:
www.yezeng.org has address 127.0.0.1
3、通过编译、二进制安装MySQL5.7多实例
#1、安装相关包
[root@localhost ~]# yum -y install libaio numactl-libs
#2、创建用户和组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql
#3、准备程序文件
[root@localhost ~]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
[root@localhost ~]# tar xf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ll /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.29-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# chown -R root.root /usr/local/mysql/
#4、准备环境变量
[root@localhost local]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh
#5、准备配置文件
[root@localhost ~]# cp /etc/my.cnf{,.bak}
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
#6、生成数据库文件,并提取root密码
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/data/mysql
[root@localhost ~]# grep password /data/mysql/mysql.log
2021-03-23T01:31:47.545591Z 1 [Note] A temporary password is generated for root@localhost: g++hZj+BI8lH
[root@localhost ~]# awk '/temporary password/{print $NF}' /data/mysql/mysql.log
g++hZj+BI8lH
#7、准备服务脚本和启动
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chkconfig --add mysqld
Starting MySQL. SUCCESS!
[root@localhost ~]# service mysqld status
SUCCESS! MySQL running (8590)
#8、修改口令
mysqladmin -uroot -p'g++hZj+BI8lH' password 123456
#9、测试登录
mysql -uroot -p123456
4、整理MySQL数据类型
mysql 中数据类型主要有三种
文本.数字 ,日期/时间
文本类型:char 定长,varchar变长,都是最多65535,char多了会截取,varchar少了自动补长.text最多65535,blob也是最多65535,blob可存二进制,图片音乐转存,enum和set枚举,enum65535个,set64个可多选.longtext,mediumtext和mediumblog存的可以更大.
数字: int1 和int 10没啥区别,int10会补0,float,dobule存的不精确,decimal精确,不精确计算可用bcadd,bcsub系列
日期: date 日期,datetime日期加时间,timestamp时间戳,time()时间,
***int(10)跟存储没关系,只是补0的显示宽度, float|double(M,D) m长度,d小数长度,会四舍五入,decimal默认整数,time时间加上日期自动转换成小时.set可多个标签,enum一个性别,
float 单精度总长为8 ,double双精度总长为16.如果超过了精度的总长度则实际存储仍未总长度.timestamp会随着掐字段的修改而自动更新,所以这个字段存储的是自动更新的内容.