网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[root@localhost ~]# vi /etc/sysctl.conf
[root@localhost ~]# sysctl -p
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
二,安装配置nginx服务
配置IP地址
第一台Nginx服务器
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.3 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::20c:29ff:fe1c:a1a4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1c:a1:a4 txqueuelen 1000 (Ethernet)
RX packets 17151 bytes 1481642 (1.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9028 bytes 904486 (883.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.7.1 netmask 255.255.255.0 broadcast 192.168.7.255
inet6 fe80::20c:29ff:fe1c:a1ae prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1c:a1:ae txqueuelen 1000 (Ethernet)
RX packets 250 bytes 45678 (44.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 47 bytes 7062 (6.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
第二台Nginx服务器
[root@localhost network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.4 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::20c:29ff:feb5:b978 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:b5:b9:78 txqueuelen 1000 (Ethernet)
RX packets 15495 bytes 1572697 (1.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7750 bytes 817696 (798.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.7.2 netmask 255.255.255.0 broadcast 192.168.7.255
inet6 fe80::20c:29ff:feb5:b982 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:b5:b9:82 txqueuelen 1000 (Ethernet)
RX packets 155 bytes 16854 (16.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 283 bytes 46422 (45.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
安装依赖关系安装包
[root@localhost ~]# yum -y install pcre-devel zlib-devel
创建nginx需要指定的组
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
解压nginx源代码包,配置,编译,安装
[root@localhost ~]# tar zxf /mnt/nginx-1.12.0.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.12.0/
[root@localhost nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
[root@localhost nginx-1.12.0]# make && make install
优化路径,将nginx可用执行执行
[root@localhost nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
开启nginx服务
[root@localhost nginx-1.12.0]# nginx
三,在(两台)Nginx服务器上配置lo:0回环VIP地址并关闭ARP重定向
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.2.54
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
[root@localhost network-scripts]# ifup ifcfg-lo:0
关闭ARP重定向
[root@localhost network-scripts]# vi /etc/sysctl.conf
[root@localhost network-scripts]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
添加VIP地址lo:0网卡路由
[root@localhost network-scripts]# route add -host 192.168.2.254 dev lo:0
四,在LVS两台服务器上配置Web服务器池的配置
[root@localhost ~]# vi /etc/keepalived/keepalived.conf
virtual_server 192.168.2.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.2.3 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.2.4 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@localhost ~]# systemctl restart keepalived
五,配置NFS共享文件服务器
配置IP地址
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.7.3 netmask 255.255.255.0 broadcast 192.168.7.255
inet6 fe80::20c:29ff:fe4f:2519 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:4f:25:19 txqueuelen 1000 (Ethernet)
RX packets 1474 bytes 240615 (234.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 827 bytes 93826 (91.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
安装NFS程序
[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@localhost ~]# systemctl enable rpcbind
设置共享目录
[root@localhost ~]# mkdir -p /opt/www
[root@localhost ~]# vi /etc/exports
/opt/www 192.168.7.0/24(rw,sync,no_root_squash)
启动NFS服务程序
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
查看本机发布的NFS共享目录
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
/opt/www 192.168.7.0/24
六,在Nginx服务器上挂载共享资源
安装rpcbind软件包,并启动rpbind服务
[root@localhost ~]# yum -y install rpcbind nfs-utils
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl start rpcbind
手动挂载NFS共享目录
[root@localhost ~]# mount 192.168.7.3:/opt/www /var/www
设置统一信息
[root@localhost ~]# echo "hello" > /var/www/index.html
浏览器测试即可
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!