1.1.2搭建好两个web服务器,实验是否搭建成功。
1.1.3搭建DNS服务器。(注:这里只需要写正向解析文件)搭建完成之后解析一下域名,看是否搭建成功。
1.1.4搭建NFS服务器,创建目录并在web服务器上挂载使用。
1.1.5搭建rsync服务器并测试是否能备份nfs服务器内容。
1.1.6在NFS服务器上安装sersync实现实时同步。
1.1.7搭建堡垒机,使远程连接只能连接堡垒机。
web服务器是搭建网站用的。
# yum -y install gcc gcc-c++ apr apr-devel cyrus-sasl-devel expat-devel libdb-devel openldap-devel apr-util-devel apr-util pcre-devel pcre lrzsz
在官网apache.org下载最新的httpd软件包(这里以httpd-2.4.48.tar.gz软件包为例)
# hostnamectl set-hostname web
# tar xf httpd-2.4.48.tar.gz -C /usr/src
把软件包解压到/usr/src/目录下。注:这里的指定路径的参数为大写的c
# cd /usr/src/httpd-2.4.28
# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
进入解压后的软件包,配置并指定安装路径。
# make && make install && echo $?
编译并安装装,且查看编译和安装装是否成功。
结果为0表示成功,结果非0表示不成功,需要从新编译及安装。
# ln -s /usr/local/httpd/bin* /usr/local/bin
创建软连接到PATH变量中。
# apachectl
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::6de9:6d50:2cc3:a0d9. Set the 'ServerName' directive globally to suppress this message
# httpd -v
Server version: Apache/2.4.48 (Unix)
Server built: Aug 20 2021 21:53:51
启动apache,查看版本信息。
# cp /usr/local//httpd/bin/apachectl /etc/init.d/httpd
# vim /etc/init.d/httpd
复制配置文件并改名,且打开配置文件。
#chkconfig: 35 81 21
#description:httpd servier
在第一行下面添加这两行内容。
# chkconfig --add httpd
# systemctl restart httpd
现在就可以使用系统服务了。
之后就可以进行访问测试,且同原理创建web02服务器。
DNS服务器最只要的作用是可以使物理机访问web服务器的是后不需要输入密码,直接输入域名即可。
# yum -y install bind-chroot bind bind-utils
# hostnamectl set-hostname dns
# systemctl start named
# systemctl enable named
# yum -y install net-tools
# netstat -anput | grep named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1217/named
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 1217/named
tcp6 0 0 ::1:53 :::* LISTEN 1217/named
tcp6 0 0 ::1:953 :::* LISTEN 1217/named
udp 0 0 127.0.0.1:53 0.0.0.0:* 1217/named
udp6 0 0 ::1:53 :::* 1217/named
# cp /etc/named.conf /var/named.conf.back
# vim /etc/named.conf
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { any; };
directory "/var/named";
allow-query { any; };
recursion yes;
forwarders { 8.8.8.8; 114.114.114.114; };
};
zone "web.com" IN {
type master;
file "web.com.zone";
};
# ll /etc/named.conf
-rw-r----- 1 root named 241 Aug 20 22:32 /etc/named.conf
# cp /var/named/named.empty /var/named/web.com.zone
这里改的名需要和之前配置文件里写的名字相同。
# vim /var/named/web.com.zone
$TTL 1D
@ IN SOA @ web.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
web.com. IN NS dns.web.com.
dns.web.com. IN A 192.168.1.4 #这里是的dns服务器的IP
www.web.com. IN A 192.168.1.2 #这里是web01服务器的IP
www.web.com. IN A 192.168.1.3 #这里是web02服务器的IP
这里是相同域名不同IP
# named-checkconf -z /etc/named.conf
zone web.com/IN: loaded serial 0
结果显示为0或者为ok表示语法没问题。
# chown :named /var/named/web.com.zone
# ll /var/named/web.com.zone
-rw-r----- 1 root named 237 Aug 20 22:36 /var/named/web.com.zone
# systemctl restart named
打开另一台虚拟机并打开网卡配置文件修改dns的IP为dns服务器的IP
在重启网卡,之后解析域名即可
# nslookup www.web.com
服务器: UnKnown
Address: 192.168.1.4
名称: www.web.com
Addresses: 192.168.1.3
192.168.1.2
nfs服务器的作用是为了两个web服务器共享网络文件的
# yum-y install rpcbind nfs-utils
修改主机名
# hostnamectl set-hostname nfs
需要在nfs服务器,web01和web02服务器上都安装命令。
# systemctl start rpcbind
# systemctl enable rpcbind
# systemctl start nfs
# systemctl enable nfs
Created symlink from /etc/systemd/system/multiuser.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
分别在nfs服务器,web01服务器和web02服务器上启动服务并设置开机自启。
# useradd -M -s /sbin/nologin -u 2000 www
分别在nfs,web01,web02三台服务器上创建用户。
# mkdir /web
创建的目录要在nfs服务器上创建。
# chown -R www:www /web
# ll -d /web
drwxr-xr-x 2 www www 6 Aug 20 23:15 /web
# vim /etc/exports
/web 192.168.1.2(rw,sync,all_squash,anonuid=2000,anongid=2000)
/web 192.168.1.3(rw,sync,all_squash,anonuid=2000,anongid=2000)
# systemctl reload nfs
# showmount -e localhost
Export list for localhost:
/web 192.168.1.3,192.168.1.2
# exportfs -v
/web 192.168.1.2(rw,sync,wdelay,hide,no_subtree_check,anonuid=2000,anongid=2000,sec=sys,secure,root_squash,all_squash)
/web 192.168.1.3(rw,sync,wdelay,hide,no_subtree_check,anonuid=2000,anongid=2000,sec=sys,secure,root_squash,all_squash)
# vim /etc/fstab
192.168.1.5:/web /usr/local/httpd/htdocs nfs defaults 0 0
# mount -a
# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 98G 1.3G 97G 2% /
devtmpfs devtmpfs 476M 0 476M 0% /dev
tmpfs tmpfs 488M 0 488M 0% /dev/shm
tmpfs tmpfs 488M 7.7M 480M 2% /run
tmpfs tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sr0 iso9660 4.2G 4.2G 0 100% /mnt/cdrom
/dev/sda1 xfs 497M 123M 375M 25% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
192.168.1.5:/web nfs4 98G 1.1G 97G 2% /usr/local/httpd/htdocs
相同的原理挂载web02服务器。
# echo "123" > /usr/local/httpd/htdocs/index.html
需要在nfs服务器上查看。
# cat /web/index.html
123
web01服务器和web02服务器上都要挂载。
作为nfs服务器实时备份的备份端服务器。
# useradd rupt && echo "rupt:1" | chpasswd
# setfacl -R -m u:rupt:rwx /nfs-back/
# setfacl -R -m d:u:rupt:rwx /nfs-back/
# hostnamectl set-hostname rsync
# mkdir /nfs-back
[root@rsync ~]# getfacl /nfs-back/
getfacl: Removing leading '/' from absolute path names
# file: nfs-back/
# owner: root
# group: root
user::rwx
user:rupt:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:rupt:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
# yum -y install rsync
需要在nfs服务器上也安装命令。
# chown -R rupt:rupt /nfs-back/
# ll -d /nfs-back/
drwxrwxr-x+ 2 rupt rupt 6 Aug 21 00:42 /nfs-back/
在nfs服务器上的/web目录中创建一个文件
[root@nfs ~]# echo "123" > /web/1.txt
[root@nfs ~]# rsync -avz --delete /web/ [email protected]:/nfs-back
The authenticity of host '192.168.1.6 (192.168.1.6)' can't be established.
ECDSA key fingerprint is SHA256:Qb8j3RAgCnkdywVUxprkutcdxESNw64buWzrKWEjGq8.
ECDSA key fingerprint is MD5:0e:04:2f:bd:a9:44:9c:bb:38:c2:0a:0a:c7:d3:83:a8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.6' (ECDSA) to the list of known hosts.
[email protected]'s password:
sending incremental file list
./
1.txt
sent 115 bytes received 38 bytes 34.00 bytes/sec
total size is 4 speedup is 0.03
显示成功。
在人sync服务器上查看一下
[root@rsync ~]# cat /nfs-back/1.txt
123
表示成功
在nfs服务器上创建密钥对
[root@nfs ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0rbsOJ04p2YyH47h1mzGESCzhV0ciZblKvmBhOYMFVI root@nfs
The key's randomart image is:
+---[RSA 2048]----+
|..E+ *+o |
| ++ B.o |
|o..* .. |
|=..o ... |
| o+ o ..S |
| o ..+ . |
| o+.+o. |
| .++%++ |
| .oO==. |
+----[SHA256]-----+
这里不需要给私钥设置密码。
[root@nfs ~]# ssh-copy-id -i [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: #这里输入用户rupt的密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
在nfs服务器上创建文件并测试
[root@nfs ~]# touch /web/2.txt
[root@nfs ~]# rsync -avz --delete /web/ [email protected]:/nfs-back
sending incremental file list
./
2.txt
sent 129 bytes received 38 bytes 334.00 bytes/sec
total size is 4 speedup is 0.02
[root@rsync ~]# ls /nfs-back/
1.txt 2.txt
显示成功。
需要在备份端完成。
首先备份配置文件
# cp /etc/rsyncd.conf rsycnd.conf.back
# vim /etc/rsyncd.conf
uid = root
gid = root
address = 192.168.1.6
port = 873
hosts allow =192.168.1.0/24
use chroot = yes
max connections = 5
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/run/rsyncd.log
motd file = /etc/rsyncd.motd
[abc]
path = /nfs-back
comment = XXX
read only = false
list = yes
auth users = backuper
secrets file = /etc/rsyncd.passwd
# echo "Welocm to Backup Server" > /etc/rsyncd.motd
[root@rsync ~]# vim /etc/rsyncd.passwd
[root@rsync ~]# cat /etc/rsyncd.passwd
backuper:1
# chmod 600 /etc/rsyncd.passwd
这里的权限必须是600的权限。
[root@rsync ~]# rsync --daemon --config=/etc/rsyncd.conf
[root@rsync ~]# echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.d/rc.local
[root@rsync ~]# chmod +x /etc/rc.d/rc.local
在nfs服务器上创建文件。
[root@nfs ~]# rsync -avz --delete /web/ [email protected]::abc
Welocm to Backup Server
Password:
sending incremental file list
./
3.txt
sent 156 bytes received 44 bytes 133.33 bytes/sec
total size is 4 speedup is 0.02
[root@rsync ~]# ls /nfs-back/
1.txt 2.txt 3.txt
显示成功。
这里做的免密是虚拟用户的免密
[root@nfs ~]# vim /etc/rsyncd.passwd
[root@nfs ~]# cat /etc/rsyncd.passwd
1
修改权限
[root@nfs ~]# chmod 600 /etc/rsyncd.passwd
测试
[root@nfs ~]# rsync -avz --delete /web/ [email protected]::abc --password-file=/etc/rsyncd.passwd
Welocm to Backup Server
sending incremental file list
./
6.txt
sent 170 bytes received 38 bytes 138.67 bytes/sec
total size is 4 speedup is 0.02
[root@nfs ~]# rz -E
rz waiting to receive.
[root@nfs ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# mv GNU-Linux-x86/ /opt/sersync
[root@nfs ~]# cd /opt/sersync/
[root@nfs sersync]# ls
confxml.xml sersync2
[root@nfs sersync]# cp confxml.xml confxml.xml.back
[root@nfs sersync]# vim confxml.xml
24 <localpath watch="/web">
25 <remote ip="192.168.1.6" name="abc"/>
26 <!--<remote ip="192.168.8.39" name="tongbu"/>-->
27 <!--<remote ip="192.168.8.40" name="tongbu"/>-->
28 </localpath>
29 <rsync>
30 <commonParams params="-artuz"/>
31 <auth start="true" users="backuper" passwordfile="/etc/rsyncd .passwd"/>
修改第24行25行和31行的内容
[root@nfs sersync]# vim confxml.xml
[root@nfs sersync]# /opt/sersync/sersync2 -d -r -o /opt/sersync/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: /opt/sersync/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is backuper
passwordfile is /etc/rsyncd.passwd
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /web && rsync -artuz -R --delete ./ [email protected]::abc --password-file=/etc/rsyncd.passwd >/dev/null 2>&1
run the sersync:
watch path is: /web
[root@nfs sersync]# echo "/opt/sersync/sersync2 -d -r -o /opt/sersync/confxml.xml" > /etc/rc.d/rc.local
[root@nfs sersync]# chmod +x /etc/rc.d/rc.local
[root@nfs sersync]# touch /web/qqq.txt
[root@rsync ~]# ls /nfs-back/
1.txt 2.txt 3.txt 6.txt qqq.txt
使用远程连接的时候只能连接到堡垒机才能连接连个web服务器,dns服务器,nfs服务器和rsync服务器进行维护。
分别在两个web服务器,dns服务器,nfs服务器和rsync服务器上创建admin用户并设置密码。
# useradd admin && echo "admin:1" | chpasswd
# vim /etc/sudoers
admin ALL=(ALL) NOPASSWD:/bin/bash
# vim /etc/ssh/sshd_config
UseDNS yes
AllowUsers [email protected]
# systemctl restart sshd
# hostnamectl set-hostname jumpserver
# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:QH++hNC38kWzv7PwZCdm/DACWnayaMoczj7f3pd44E0 root@dns
The key's randomart image is:
+---[RSA 2048]----+
| . |
| . o |
| o o o o |
| o = o o |
| S O + |
| O B.oE |
| . + +.o=@..|
| =.+ . .oO*B |
| .Bo..o .o+o.|
+----[SHA256]-----+
分别发送公钥到两个web服务器,dns服务器,nfs服务器,rsync服务器和堡垒机上。(修改后面的ip即可)
# ssh-copy-id -i [email protected]
在堡垒机上安装。
# yum -y install lrzsz
发送私钥到windows中。
# sz .ssh/id_rsa