首頁  >  文章  >  系統教程  >  Nginx 叢集負載平衡器

Nginx 叢集負載平衡器

WBOY
WBOY原創
2024-07-27 09:19:521011瀏覽

實驗環境:

10.10.204.62 Load Balancing

10.10.204.63 Nginx Web server

10.10.204.64 Nginx Web server

10.10.204.65 File Storage

Nginx 集群负载均衡器

1.File Storage 伺服器安裝

yum -y install nfs-utils

2.配置NFS並建立共享目錄

# mkdir -p /Data/webapp
# vim /etc/exports

/Data/webapp 10.10.204.0/24(rw,sync,no_subtree_check,no_root_squash)

3.開啟自啟動

# systemctl enable rpcbind
# systemctl enable nfs-server
# systemctl start rpcbind
# systemctl start nfs

4.相關參數:

rw:read-write:可读写; ro:read-only,只读; sync:文件同时写入硬盘和内存。
no_root_squash:来访的root用户保持root帐号权限;显然开启这项是不安全的。
root_squash:将来访的root用户映射为匿名用户或用户组;通常它将使用nobody或nfsnobody身份。
all_squash:所有访问用户都映射为匿名用户或用户组;
anonuid:匿名用户的UID值,可以在此处自行设定。 anongid:匿名用户的GID值。
sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性。
async:文件暂存于内存,而不是直接写入内存。
no_subtree_check :即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率。

5.File Storage 伺服器防火牆設定

# firewall-cmd --permanent --add-service=rpc-bind
# firewall-cmd --permanent --add-service=nfs
# firewall-cmd --reload

6.Nginx Web server 伺服器安裝以及掛載

# yum -y install nfs-utils
# mkdir -p /Data/webapp
# mount -t nfs 10.10.204.65:/Data/webapp /Data/webapp

7.如果需要開機自動掛載,在該文件最下方添加一行即可

# vim /etc/fstab
10.10.204.65:/Data/webapp /Data/webapp nfs auto,rw,vers=3,hard,intr,tcp,rsize=32768,wsize=32768 0 0
 

8.Nginx Web server 伺服器測試
連續寫16384個16KB的區塊到nfs目錄下的testfile檔

# time dd if=/dev/zero of=/Data/webapp/testfile bs=16k count=16384

  16384+0 records in
  16384+0 records out
  268435456 bytes (268 MB) copied, 2.89525 s, 92.7 MB/s
  real 0m2.944s
  user 0m0.015s
  sys 0m0.579s

测试读的性能

# time dd if=/nfsfolder/testfile of=/dev/null bs=16k
  16384+0 records in
  16384+0 records out
  268435456 bytes (268 MB) copied, 0.132925 s, 2.0 GB/s
  real 0m0.138s
  user 0m0.003s
  sys 0m0.127s

綜合來講,NFS的速度還算理想。如果覺得速度慢,那麼加入相關參數後,重複掛載卸載並測試讀寫,找到適合自己的配置方案。

以上是Nginx 叢集負載平衡器的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn