Linux Learning-Week 16

1. Briefly describe the principle of the DNS server, and set up a primary-secondary server.

(1) Take the client request www.magedu.com as an example to describe the principle of the DNS server:
1) Query the /etc/hosts file on the machine to see if there is an IP address corresponding to www.magedu.com
2) Query the machine DNS service cache on the Internet to see if there is an IP address record corresponding to
www.magedu.com 3) Send the request to the DNS proxy resolution server configured on the host (such as 223.5.5.5), and the DNS proxy resolution server forwards the user request to DNS cache server queries, if there is no result
4) DNS proxy resolution server forwards the user request to the root server
5) The root server returns the IP of the .com domain name server, and the DNS proxy resolution server forwards the user request to the .com domain server
6). The com domain name server returns the IP of the magedu.com domain name server, and the DNS proxy resolution server forwards the user request to the magedu.com domain name server.
7) The magedu.com domain name server queries the local configuration file to get the corresponding IP, and returns the query result to the DNS proxy for resolution Server
8) The DNS proxy resolution server sends www.magedu.com and the corresponding IP to the DNS cache server for storage, and returns the query result to the user at the same time.
9) The user gets the query result and saves it to the local DNS service cache
(2) ) Set up the main-auxiliary server:
1) Environmental requirements
need four hosts
DNS master server: 10.0.0.81
DNS slave server: 10.0.0.73
web server: 10.0.0.71
DNS client: 10.0.0.72
2) Prepare to
close SElinux in advance
Turn off firewall
time synchronization
3) Primary DNS server configuration
install DNS service
yum install bind -y
configuration /etc/named.conf
vim /etc/named.conf
comment out the following two lines
// listen-on port 53 {127.0.0.1; };
// allow-query {localhost; };
only allow zone transfer from the server
allow-transfer {from server IP;};
configure /etc/named.rfc1912.zones
vim /etc/named.rfc1912.zones
plus this Segment
zone "magedu.org" {
type master;
file "magedu.org.zone";
};
configuration /var/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.81
slave A 10.0.0.73
start the service
systemctl start named #Start the service for the first time
rndc reload #It is not the first time to start the service
4)
Install the DNS service from the DNS server configuration
yum install bind -y
configuration /etc/ named.conf
vim /etc/named.conf
comment out the following two lines
// listen-on port 53 {127.0.0.1; };
// allow-query {localhost; };
Do not allow other hosts to perform zone transfer
allow-transfer { none;};
configure /etc/named.rfc1912.zones
vim /etc/named.rfc1912.zones
zone "magedu.org" {
type slave;
masters {master server IP;};
file "slaves/magedu.org.slave" ;
};
Start the service
systemctl start named #Start the service for the first time
rndc reload #It is not the first time to start the service to
check whether the regional database file is generated
ls /var/named/slaves/magedu.org.slave
5) Client test master-slave DNS service architecture
configuration network card
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=master server
DNS2=slave server
verifies master DNS server Is it possible to query
dig www.magedu.org
curl www.magedu.org
to stop the DNS service on the master server
systemctl stop named
verify that the slave DNS server can still query
dig www.magedu.org
curl www.magedu.org

2. Build and implement smart DNS.

(1) Environmental requirements
need five hosts
DNS master server and web server 1: 10.0.0.81/24, 172.16.0.81/16
web server 2: 10.0.0.82/24
web server 3: 172.16.0.82/16
DNS client 1 : 10.0.0.71/24
DNS client 2: 172.16.0.71/16
(2) The prerequisite is to
turn off SElinux and
turn off the firewall
time synchronization
(3) DNS server network card configuration
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 fq_codel state UP group default qlen 1000
link/ether 00:0c:29:59:ff:53 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.81/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c: 29ff:fe59:ff53/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:cf:6b:b8 brd ff:ff:ff:ff:ff:ff
inet 172.16.0.81/16 brd 172.16.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
(4) The main DNS server configuration file realizes view
installation DNS service
yum install bind -y
configuration /etc/named.conf
vim /etc/named.conf
Add the following line at the top of the file
acl beijingnet {
192.168.8.0/24;
};
acl shanghainet {
172.16.0.0/16;
};
acl othernet {
any;
};
comment out the following two lines
// listen-on port 53 {127.0.0.1; };
// allow-query {localhost; };
create 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";
(5) Implement zone configuration file
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 (6) Create a zone database file
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 10.0.0.81
websrv A 10.0.0.82
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 172.16.0.81
websrv A 172.16.0.82
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 10.0.0.81
websrv A 127.0.0.1
www CNAME websrv
modify the group
chgrp named /var/named/magedu.org.zone.bj
chgrp named /var/named/magedu.org.zone.sh
chgrp named /var/named/magedu.org.zone.other
Start the service
systemctl start named #Start the service for the first time
rndc reload #It is not the first time to start the service
(7) Implementation Three WEB servers located in different regions
install http services on the three hosts respectively
. Implement
yum install httpd
echo www.magedu.org in Other> /var/www/html/index.html on the web server 1: 10.0.0.81/24
systemctl start httpd
on web server 2: 10.0.0.82/24
yum install httpd
echo www.magedu.org in Beijing> /var/www/html/index.html
systemctl start httpd
on web server 3: 172.16.0.81/16
yum install httpd
echo www.magedu.org in Shanghai> /var/www/html /index.html
systemctl start httpd
(8) The client test
is to access the
DNS client 1: 10.0.0.71/24 on three hosts respectively . Make sure that the DNS points to 10.0.0.81
curl www.magedu.org www.magedu.org
in Beijing
DNS client 2: 172.16.0.71/16 implementation, ensure that DNS points to 172.16.0.81
curl www.magedu.org www.magedu.org
in Shanghai
DNS client 3: 10.0.0.81 implementation, ensure that DNS points to 127.0.0.1
curl www.magedu.org
www.magedu.org in Other

3. Install MySQL5.7 through compilation and binary

(1) Compile and install mysql 5.7.32 from source code
1) Install related dependencies
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
2) Prepare the user and data directory
useradd -r -s /sbin/nologin -d /data/mysql mysql
3) Prepare the database directory
mkdir /data/mysql
chown mysql.mysql /data/ mysql
4) Compile and install source code
Download and unzip the source package
tar xvf mysql-5.7.32.tar.gz
Compile and install source code mariadb
cd mysql-5.7.32/
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_APWITH_system \
-DWITH_APWITH_system \
-DWITH_DATA\
INABLE_DATA \ -DWITH_DENABLE=1 -DWITH_SQL /mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
5) Prepare environment variables echo'PATH=
/app/mysql/bin:$PATH'> /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
6) Generate database file
cd /app/mysql/
scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
7) Prepare configuration file
cp /app/mysql/ support-files/my-huge.cnf /etc/my.cnf
8) Prepare the startup script and start the service
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
9) Securely initialize
mysql_secure_installation
(2) Binary installation of MySQL 5. 7
1) Install related packages
yum -y install libaio numactl-libs
2) Create users and groups
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
3) Prepare program files
tar xf mysql-5.7.29-linux- glibc2.12-x86_64.tar.gz --C /usr/local
cd /usr/local/
ln -s mysql-5.7.29-linux-glibc2.12-x86_64/ mysql
chown -R root.root /usr/local/ mysql/
4) Prepare the environment variable
echo'PATH=/usr/local/mysql/bin:$PATH'> /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
5) Prepare the configuration file
cp /etc/my.cnf{,.bak}
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) Generate a database file and extract the root password
mysqld --initialize --user=mysql --datadir=/data/mysql
... omitted...
2019-07-04T13:03:54.258140Z 1 [Note] A temporary password is generated for
root@localhost: LufavlMka6,! #Note that the initial password of root is generated
grep password /data/mysql/mysql.log
2019-12-26T13: 31:30.458826Z 1 [Note] A temporary password is generated for
root@localhost: LufavlMka6,!
awk'/temporary password/{print $NF}' /data/mysql/mysql.log
LufavlMka6,!
7) Prepare the service script and start
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
8) Modify the password
mysqladmin -uroot -p'LufavlMka6, !'password magedu
9) Test login
mysql -uroot -pmagedu

Guess you like

Origin blog.51cto.com/14255962/2676171