数据库
首页 > 数据库> > 主辅及智能DNS实现与MySQL5.7.32编译安装

主辅及智能DNS实现与MySQL5.7.32编译安装

作者:互联网

[主辅及智能DNS实现与MySQL5.7.32编译安装]()

一、DNS服务原理

DNS服务原理

当前TCP/IP网络中的设备之间进行通信,是利用和依赖于IP地址实现的。而人们在使用网络资源的时,那种由文字组成的资源名称,更容易记忆和使用,但是计算机不理解这种名称。DNS( Domain Name System)名字解析服务,能够将人们使用的名称翻译成(解析)成计算机能够理解的IP地址,从而解决了此问题。

DNS:Domain Name System 域名系统,应用层协议,是互联网的一项服务。它作为将域名和IP地址相互映射的一个分布式数据库,包含各种资源记录。从域名到IP地址的解析是由分布在因特网上的许多域名服务器程序共同完成的,因为因特网规模很大,所以整个因特网只使用一个域名服务器是不可行的,早在1983年因特网开始采用层次树状结构的命名方法。

主辅及智能DNS实现与MySQL5.7.32编译安装

一个DNS服务器所负责管辖(或有权限)的范围叫做区(zone),需要根据具体情况来划分管辖范围的区。在一个区中的所有节点必须是能够连通的,每一个区设置相应的权限域名服务器,用来保存该区中的所有主机到域名IP地址的映射。DNS服务器的管辖范围不都是以“域”为单位,有时是以“区”为单位,区 <= 域。

主辅及智能DNS实现与MySQL5.7.32编译安装

上图中假定abc公司有下属部门x和y,部门x下面有分三个分布们u,v,w,而y下面还有下属部门t。图a表示abc公司只设一个区abc.com。这时区abc.com和域abc.com指的是同一件事。但图b表示abc公司划分为两个区:abc.com和y.abc.com。这两个区都隶属于域abc.com,都各设置了相应的权限域名服务器。不难看出,区是域的子集。

区域解析库:由众多RR组成:

DNS 查询的过程如下图:

主辅及智能DNS实现与MySQL5.7.32编译安装

  1. 在浏览器中输入www.qq.com域名,操作系统会先检查自己本地的hosts文件是否有这个网址映射关系,如果有,就使用这个IP地址映射,完成域名解析。
  2. 如果hosts里没有这个域名的映射,则查找本地DNS解析器缓存,是否有这个网址映射关系,如果有,直接返回,完成域名解析。
  3. 如果hosts与本地DNS解析器缓存都没有相应的网址映射关系,首先会找TCP/ip参数中设置的首选DNS服务器,在此我们叫它本地DNS服务器,此服务器收到查询时,如果要查询的域名,包含在本地配置区域资源中,则返回解析结果给客户机,完成域名解析,此解析具有权威性。
  4. 如果要查询的域名,不由本地DNS服务器区域解析,但该服务器已缓存了此网址映射关系,则调用这个IP地址映射,完成域名解析,此解析不具有权威性。
  5. 如果本地DNS服务器本地区域文件与缓存解析都失效,则根据本地DNS服务器的设置(是否设置转发器)进行查询,如果未用转发模式,本地DNS就把请求发至13台根DNS,根DNS服务器收到请求后会判断这个域名(.com)是谁来授权管理,并会返回一个负责该顶级域名服务器的一个IP。本地DNS服务器收到IP信息后,将会联系负责.com域的这台服务器。这台负责.com域的服务器收到请求后,如果自己无法解析,它就会找一个管理.com域的下一级DNS服务器地址(qq.com)给本地DNS服务器。当本地DNS服务器收到这个地址后,就会找qq.com域服务器,重复上面的动作,进行查询,直至找到www.qq.com主机。
  6. 如果用的是转发模式,此DNS服务器就会把请求转发至上一级DNS服务器,由上一级服务器进行解析,上一级服务器如果不能解析,或找根DNS或把转请求转至上上级,以此循环。不管是本地DNS服务器用是是转发,还是根提示,最后都是把结果返回给本地DNS服务器,由此DNS服务器再返回给客户机。

二、搭建主辅DNS服务

2.1 测试环境:

DNS Maste DNS Slave httpd
系统版本:CentOS Linux release 8.1.1911 (Core) 系统版本:CentOS Linux release 8.1.1911 (Core) 系统版本:CentOS Linux release 7.8.2003 (Core)
软件:bind-32:9.11.20-5.el8_3.1.x86_64 软件:bind-32:9.11.20-5.el8_3.1.x86_64 软件:httpd.x86_64 0:2.4.6-97.el7.centos
IP:172.20.200.201 IP:172.20.200.202 IP:172.20.200.131

2.2 Maste端安装配置bind为www.dongbei.org解析

[root@master ~]#yum install -y  bind

#编辑bind主配置文件
[root@master ~]# vim /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     {172.20.200.0/24 ; };        #允许172.20.200网段查询

    dnssec-enable no;       #关闭
    dnssec-validation no;   #关闭

#编辑include配置文件/etc/named.rfc1912.zones,增加dongbei.org.zone
[root@master ~]# vim /etc/named.rfc1912.zones
zone "dongbei.org" IN {
    type master;
    file "dongbei.org.zone";
};                              

#创建dongbei.org.zone文件
[root@master ~]# cp -p /var/named/named.localhost /var/named/dongbei.org.zone
[root@master ~]# vim /var/named/dongbei.org.zone
$TTL 1D
@   IN SOA  master admin.dongbei.org. (
                    0   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    NS  master
master  A   172.20.200.201
www     A   172.20.200.131   

[root@master named]# chown named:named /var/named/dongbei.org.zone
[root@master named]# named-checkconf
[root@master var]# named-checkzone dognbei.org /var/named/dongbei.org.zone 
zone dognbei.org/IN: loaded serial 0
OK
[root@master named]# systemctl enable --now named
Created symlink /etc/systemd/system/multi-user.target.wants/named.service → /usr/lib/systemd/system/named.service.

2.3 httpd端安装配置

[root@localhost ~]# yum instal -y httpd
[root@localhost ~]# echo www.dongbei.org > /var/www/html/index.html
[root@localhost ~]# systemctl start httpd

2.4 验证Master解析www.dongbei.org

[root@slave ~]# host www.dongbei.org 172.20.200.201
Using domain server:
Name: 172.20.200.201
Address: 172.20.200.201#53
Aliases: 

www.dongbei.org is an alias for websrv.dongbei.org.
websrv.dongbei.org has address 172.20.200.131
[root@slave ~]# 

2.5 为增加slaver端调整master端配置

#named主配置
[root@master etc]# vim /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     {172.20.200.0/24 ; };
    allow-transfer  {172.20.200.202;};  #允许slaver进行区域传输

#区域数据文件
[root@master etc]# vim /var/named/dongbei.org.zone 
$TTL 1D
@   IN SOA  master admin.dongbei.org. (
                    1   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    NS  master
    NS  slaver        #增加slaver记录                                                                                                              
master  A   172.20.200.201
slaver  A   172.20.200.202  #增加slaver记录 
www     A   172.20.200.131

#master端读取调整后的配置文件
[root@master etc]# rndc reload
server reload successful

2.6 Slave端安装配置bind

[root@slave ~]# yum install -y bind
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     { 172.20.200.0/24; };
    allow-transfer  {none;};    #不允许区域传送                               
    dnssec-enable no;      
    dnssec-validation no;

[root@slave ~]# vim /etc/named.rfc1912.zones
zone "dongbei.org" IN {
    type slave;
    file "slaves/dongbei.org";
    masters {172.20.200.201;};
};                                
[root@slave slaves]# named-checkconf
[root@slave slaves]# systemctl enable --now named
Created symlink /etc/systemd/system/multi-user.target.wants/named.service → /usr/lib/systemd/system/named.service.

[root@slave slaves]# ls /var/named/slaves/
dongbei.org

2.7 验证slaver端是否正常解析

[root@slave ~]# host www.dongbei.org 172.20.200.202
Using domain server:
Name: 172.20.200.202
Address: 172.20.200.202#53
Aliases: 

www.dongbei.org has address 172.20.200.131
[root@slave ~]# 

2.8 验证主辅之间数据同步

#在master端增加A记录
[root@master etc]# vim /var/named/dongbei.org.zone
$TTL 1D
@   IN SOA  master admin.dongbei.org. (
                    5   ; serial        #手动增加版本号                                                                                          
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    NS  master
    NS  slaver
master  A   172.20.200.201
slaver  A   172.20.200.202
www     A   172.20.200.131
web1    CNAME  www              #新增加
web2   A    172.20.200.202      #新增加
web3   A    1.1.1.1             #新增加

[root@master etc]# rndc reload
server reload successful

#用master端查询
[root@master etc]# host web2.dongbei.org 172.20.200.201
Using domain server:
Name: 172.20.200.201
Address: 172.20.200.201#53
Aliases: 

web2.dongbei.org has address 172.20.200.202

[root@master etc]# host web3.dongbei.org 172.20.200.201
Using domain server:
Name: 172.20.200.201
Address: 172.20.200.201#53
Aliases: 

web3.dongbei.org has address 1.1.1.1

#用slaver端查询
[root@master etc]# host web2.dongbei.org 172.20.200.202
Using domain server:
Name: 172.20.200.202
Address: 172.20.200.202#53
Aliases: 

web2.dongbei.org has address 172.20.200.202

[root@master etc]# host web3.dongbei.org 172.20.200.202
Using domain server:
Name: 172.20.200.202
Address: 172.20.200.202#53
Aliases: 

web3.dongbei.org has address 1.1.1.1

三、搭建并实现智能DNS

3.1 测试环境

DNS Server Client
系统版本:CentOS Linux release 8.1.1911 (Core) 系统版本:CentOS Linux release 8.1.1911 (Core)
软件:bind-32:9.11.20-5.el8_3.1.x86_64 工具:host
IP:172.20.200.201 192.168.16.130 192.168.17.130 IP:172.20.200.202 192.168.16.129 192.168.17.129
172.20.200.0/24 Vmnet0网段 192.168.16.0 /24 Vmnet1网段192.168.17.0/24 Vmnet2网段 172.20.200.0/24 Vmnet0网段 192.168.16.0 /24 Vmnet1网段192.168.17.0/24 Vmnet2网段

3.2 DNS Server配置

#DNS Server网络IP
[root@master ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.201  netmask 255.255.0.0  broadcast 172.20.255.255
        inet6 fe80::d345:3753:82b4:4e14  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::8d83:991b:3df5:2457  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ee:87:6a  txqueuelen 1000  (Ethernet)
        RX packets 432  bytes 41265 (40.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 287  bytes 27866 (27.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:ee:87:74  txqueuelen 1000  (Ethernet)
        RX packets 177  bytes 16889 (16.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 18  bytes 1444 (1.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 10  bytes 750 (750.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10  bytes 750 (750.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

#更改/etc/named.conf
 acl dongbeinet {
        172.20.200.0/24;
        };  
    acl huabeinet {
        192.168.16.0/24;
        };  
    acl othernet {
        any;
        };  

    view dongbeiview {
    match-clients { dongbeinet;};
    include "/etc/named.rfc1912.zones.db";
    };

    view shanghaiview {
    match-clients { huabeinet;};
    include "/etc/named.rfc1912.zones.hb";
    };

    view otherview {
    match-clients { othernet;};
    include "/etc/named.rfc1912.zones.other";
    };

options {

//  listen-on port 53 { 127.0.0.1; };
//  listen-on-v6 port 53 { ::1; };

    allow-query     {any; };   #允许所有客户端查询
    allow-transfer  {172.20.200.202;};

   dnssec-enable no;
   dnssec-validation no;

#使用了view就不能使用zones   
//   zone "." IN {
//    type hint;
//    file "named.ca";
//  };

//include "/etc/named.rfc1912.zones";

#创建区域配置文件
[root@master ~]# vim /etc/named.rfc1912.zones.db
zone "." IN {
    type hint;
    file "named.ca";
    };  
zone "dongbei.org" {
    type master;
    file "dongbei.org.zone.db";
    };  

[root@master ~]# vim /etc/named.rfc1912.zones.hb
zone "." IN {
    type hint;
    file "named.ca";
    };  
zone "dongbei.org" {
    type master;
    file "dongbei.org.zone.hb";
    };  

[root@master ~]# vim /etc/named.rfc1912.zones.other
zone "." IN {
    type hint;
    file "named.ca";
    };  
zone "dongbei.org" {
    type master;
    file "dongbei.org.zone.other";                                                                                               
    };  

[root@master ~]# chgrp named /etc/named.rfc1912.zones.db
[root@master ~]# chgrp named /etc/named.rfc1912.zones.hb
[root@master ~]# chgrp named /etc/named.rfc1912.zones.other

#创建区域数据文件
[root@master ~]# cp -p /var/named/dongbei.org.zone /var/named/dongbei.org.zone.db
[root@master ~]# vim /var/named/dongbei.org.zone.db
TTL 1D
@   IN SOA  master admin.dongbei.org. (
                    5   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    NS  master
    NS  slaver
master  A   172.20.200.201
slaver  A   172.20.200.202
websrv     A   172.20.200.131
www    CNAME  websrv                       

[root@master ~]# cp -p /var/named/dongbei.org.zone.db /var/named/dongbei.org.zone.hb
[root@master ~]# vim /var/named/dongbei.org.zone.hb
$TTL 1D
@   IN SOA  master admin.dongbei.org. (
                    5   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    NS  master
    NS  slaver
master  A   172.20.200.201
slaver  A   172.20.200.202

websrv     A   192.168.16.128                                                                                                    
www    CNAME  websrv 

[root@master ~]# cp -p /var/named/dongbei.org.zone.db /var/named/dongbei.org.zone.other
[root@master ~]# vim /var/named/dongbei.org.zone.other
$TTL 1D
@   IN SOA  master admin.dongbei.org. (
                    5   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
    NS  master
    NS  slaver
master  A   172.20.200.201
slaver  A   172.20.200.202
websrv     A   192.168.17.128                                                                                                    
www    CNAME  websrv 

#检查配置及数据库文件
[root@master ~]# named-checkconf 
[root@master ~]# 

[root@master ~]# named-checkzone dongbei.org /var/named/dongbei.org.zone.db
zone dongbei.org/IN: loaded serial 5
OK
[root@master ~]# named-checkzone dongbei.org /var/named/dongbei.org.zone.hb
zone dongbei.org/IN: loaded serial 5
OK
[root@master ~]# named-checkzone dongbei.org /var/named/dongbei.org.zone.other
zone dongbei.org/IN: loaded serial 5
OK

[root@master ~]# rndc reload
server reload successful

3.3 Client端解析测试

#Client端IP配置
[root@client ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.202  netmask 255.255.0.0  broadcast 172.20.255.255
        inet6 fe80::d345:3753:82b4:4e14  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::8d83:991b:3df5:2457  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:90:19:8f  txqueuelen 1000  (Ethernet)
        RX packets 7330  bytes 9437007 (8.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3105  bytes 250659 (244.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.16.129  netmask 255.255.255.0  broadcast 192.168.16.255
        inet6 fe80::6a3d:e71e:96d5:1121  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:90:19:99  txqueuelen 1000  (Ethernet)
        RX packets 58  bytes 6286 (6.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1253 (1.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.17.129  netmask 255.255.255.0  broadcast 192.168.17.255
        inet6 fe80::4462:d510:5e28:af6f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:90:19:a3  txqueuelen 1000  (Ethernet)
        RX packets 72  bytes 8779 (8.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 26  bytes 2642 (2.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 41  bytes 2352 (2.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 41  bytes 2352 (2.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 #解析测试
 [root@client ~]# host www.dongbei.org 172.20.200.201
Using domain server:
Name: 172.20.200.201
Address: 172.20.200.201#53
Aliases: 
www.dongbei.org is an alias for websrv.dongbei.org.
websrv.dongbei.org has address 172.20.200.131

[root@client ~]# host www.dongbei.org 192.168.16.130
Using domain server:
Name: 192.168.16.130
Address: 192.168.16.130#53
Aliases: 
www.dongbei.org is an alias for websrv.dongbei.org.
websrv.dongbei.org has address 192.168.16.128

[root@client ~]# host www.dongbei.org 192.168.17.130
Using domain server:
Name: 192.168.17.130
Address: 192.168.17.130#53
Aliases: 
www.dongbei.org is an alias for websrv.dongbei.org.
websrv.dongbei.org has address 192.168.17.128
[root@client ~]# 

四、通过编译二进制安装MySQL5.7.32

4.1 编译安装MySQL5.7.32

4.1.1 系统环境

CentOS Linux release 7.8.2003 (Core) IP:172.20.200.131 Mem:4G CPU: 8 Core

4.1.2 下载MySQL5.7.32

MySQL5.7官方下载:https://downloads.mysql.com/archives/community/

下载二进制RPM bundle

主辅及智能DNS实现与MySQL5.7.32编译安装

源码下载

主辅及智能DNS实现与MySQL5.7.32编译安装

4.1.3 安装依赖软件

[root@localhost ~]# yum -y install openssl openssl-devel gcc gcc-c++  m4 cmake
[root@localhost ~]# yum install -y libaio-devel ncurses-devel numactl-devel 
[root@localhost ~]# yum install -y perl\(Env\) perl\(JSON\) time cyrus-sasl-devel openldap-devel

#安装bison,Linux 下 C/C++语法分析器
[root@localhost home]# wget http://ftp.gnu.org/gnu/bison/bison-3.7.tar.gz
[root@localhost home]# tar xf bison-3.7.tar.gz
[root@localhost home]# cd bison-3.7
[root@localhost home]# ./configure  && make && make install

#安装boost,从MySQL 5.7.5 开始Boost库是必需的,需要boost1.59.0 或以上版本
[root@localhost home]# cd /usr/local/
[root@localhost local]# wget https://sourceforge.net/projects/boost/files/boost/1.75.0/boost_1_75_0.tar.bz2
[root@localhost local]# tar xfj boost_1_75_0.tar.bz2
[root@localhost local]# yum install -y bzip2-devel.x86_64
[root@localhost local]# yum install -y python-devel
[root@localhost local]# cd boost_1_75_0
[root@localhost boost_1_75_0]# ./bootstrap.sh --with-libraries=system,filesystem,log,thread --with-toolset=gcc
[root@localhost boost_1_75_0]# ./b2 toolset=gcc cxxflags="-std=c++11"
[root@localhost boost_1_75_0]# ./b2 install --prefix=/usr/local/boost

#创建mysql用户与mysql用户组
[root@localhost boost]# groupadd -r mysql && useradd -r -g mysql -s /bin/false -M mysql

4.1.4 编译Mysql5.7.32 RMP文件

[root@localhost xsd]# rpmbuild --rebuild --clean mysql-community-5.7.32-1.el7.src.rpm
[root@localhost xsd]# cd /root/rpmbuild/RPMS/x86_64
[root@localhost x86_64]# ls
mysql-community-client-5.7.32-1.el7.x86_64.rpm           mysql-community-embedded-devel-5.7.32-1.el7.x86_64.rpm
mysql-community-common-5.7.32-1.el7.x86_64.rpm           mysql-community-libs-5.7.32-1.el7.x86_64.rpm
mysql-community-devel-5.7.32-1.el7.x86_64.rpm            mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm
mysql-community-embedded-5.7.32-1.el7.x86_64.rpm         mysql-community-server-5.7.32-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.32-1.el7.x86_64.rpm  mysql-community-test-5.7.32-1.el7.x86_64.rpm

4.2 二进制安装MySQL5.7.32

安装编译好的MySQL RPM软件包。

#解压官网下载的mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar,与自己编译的rpm文件一致
[root@localhost mysql]# tar xf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar 
[root@localhost mysql]# ls
mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar                 mysql-community-embedded-devel-5.7.32-1.el7.x86_64.rpm
mysql-community-client-5.7.32-1.el7.x86_64.rpm           mysql-community-libs-5.7.32-1.el7.x86_64.rpm
mysql-community-common-5.7.32-1.el7.x86_64.rpm           mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm
mysql-community-devel-5.7.32-1.el7.x86_64.rpm            mysql-community-server-5.7.32-1.el7.x86_64.rpm
mysql-community-embedded-5.7.32-1.el7.x86_64.rpm         mysql-community-test-5.7.32-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.32-1.el7.x86_64.rpm

#使用自编译的RPM文件安装
[root@localhost x86_64]#  rpm -ivh mysql-community-{server,client,common,libs}-*  --force --nodeps
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.32-1.e################################# [ 20%]
   2:mysql-community-libs-5.7.32-1.el7################################# [ 40%]
   3:mysql-community-client-5.7.32-1.e################################# [ 60%]
   4:mysql-community-server-5.7.32-1.e################################# [ 80%]
   5:mysql-community-libs-compat-5.7.3################################# [100%]
[root@localhost x86_64]# 
[root@localhost x86_64]# systemctl start mysqld
[root@localhost x86_64]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-03-26 04:00:21 CST; 15s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 29612 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 29561 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 29615 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─29615 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Mar 26 04:00:18 localhost.localdomain systemd[1]: Starting MySQL Server...
Mar 26 04:00:21 localhost.localdomain systemd[1]: Started MySQL Server.

4.3 连接MySQL并测试

#找到首次登录密码
[root@localhost x86_64]# grep 'temporary password' /var/log/mysqld.log
2021-03-25T20:00:19.024681Z 1 [Note] A temporary password is generated for root@localhost: goqspAAR7.AB
[root@localhost x86_64]# 

#用初始密码登录MySQL Server
[root@localhost x86_64]# mysql -uroot -pgoqspAAR7.AB
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.32

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

#更改'root'@'localhost'密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword!112233';   
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

#运行数据库创建脚本
mysql> source /root/hellodb_innodb.sql
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use hellodb;
Database changed
mysql> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes           |
| coc               |
| courses           |
| scores            |
| students          |
| teachers          |
| toc               |
+-------------------+
7 rows in set (0.01 sec)

mysql> select * from classes;
+---------+----------------+----------+
| ClassID | Class          | NumOfStu |
+---------+----------------+----------+
|       1 | Shaolin Pai    |       10 |
|       2 | Emei Pai       |        7 |
|       3 | QingCheng Pai  |       11 |
|       4 | Wudang Pai     |       12 |
|       5 | Riyue Shenjiao |       31 |
|       6 | Lianshan Pai   |       27 |
|       7 | Ming Jiao      |       27 |
|       8 | Xiaoyao Pai    |       15 |
+---------+----------------+----------+
8 rows in set (0.00 sec)

MySQL功能正常。

标签:named,dongbei,32,MySQL5.7,172.20,master,主辅,org,root
来源: https://blog.51cto.com/12302225/2672366