面向對象昇華:面向對象的認識----新生的初識、面向對象的番外----思想的夢遊篇(1)、面向對象的認識---如何找出類數據庫
PHP項目 起點:手把手教你作關鍵詞匹配項目(搜索引擎)---- 第一天 最新:手把手教你作關鍵詞匹配項目(搜索引擎)---- 第二十一天ubuntu
負載均衡----文件服務策略服務器
同類文章:負載均衡----概念認識篇、負載均衡----實現配置篇(Nginx)負載均衡
上回我提到的這麼多服務器,他們共同須要的文件從哪裏來?
那麼咱們就須要文件服務器,文件服務器從哪裏來,咱們先看圖瞭解下:dom
圖1分佈式
---------------------------------------------------------------------------------------------------------------ide
圖2post
無論是圖1仍是圖2都能解決問題。網站
當你拿着這兩份圖給老闆審批的時候,老闆都會選擇圖2。
這個涉及高層的問題,先不用去理會,今天咱們主要的內容是文件服務策略。
今天介紹的文件服務策略分爲三種(Linux):
1. 文件共享
2. 文件同步
3. 分佈式文件系統
三種的優缺點,本篇不做聲明。
1. 文件共享篇
參照圖2,PA爲文件服務器,文件主要存放服務器。
P1,P2,P3執行如下命令便可,你能夠把該命令放入/etc/rc.local,開機自動啓動 :
mount -o rw 192.168.2.2:/storage /storage
注:PA,P1,P2,P3 /storage爲文件路徑
2. 文件同步篇
PA安裝rsync服務端,如何安裝請查看:http://rsync.samba.org/
2.1 軟件包安裝
sudo apt-get install rsync #在debian、ubuntu 等在線安裝方法; yum install rsync #Fedora、Redhat 等在線安裝方法; rpm -ivh rsync #Fedora、Redhat 等rpm包安裝方法;
2.2 配置文件
rsync的主要有如下三個配置文件/etc/rsyncd.conf(主配置文件)、/etc/rsyncd.secrets(密碼文件)、/etc/rsyncd.motd(rysnc服務器信息)
注:rsyncd.secrets這個密碼文件的文件屬性設爲root擁有, 且權限要設爲600, 不然沒法備份成功!
/etc/rsyncd.conf:
pid file = /var/run/rsyncd.pid port = 873 address = 192.168.1.171 uid = root gid = root use chroot = yes read only = yes #limit access to private LANs hosts allow=192.168.2.0/255.255.255.0 hosts deny=* max connections = 5 #motd file = /etc/rsyncd.motd #This will give you a separate log file #log file = /var/log/rsync.log #This will log every file transferred - up to 85,000+ per user, per sync #transfer logging = yes log format = %t %a %m %f %b syslog facility = local3 timeout = 300 [storage] path = /storage list=yes ignore errors auth users = root secrets file = /etc/rsyncd.secrets
rsyncd.secrets:
root:storage@mydomain.com
2.3 啓動服務
/etc/init.d/xinetd reload
P一、P二、P3也同樣安裝rsync。
開個定時命令crontab,每幾分鐘同步一次,執行如下命令:
rsync -vzrtopg --delete root@192.168.2.2::storage --password-file=/etc/rsync.pass
爲了避免用輸入密碼,/etc/rsync.pass加入密碼
storage@mydomain.com
3. 分佈式文件系統
開始以前先看圖.
首先了解下幾個概念:
1. PA:Master文件服務器(主服務器)
2. P一、P二、P3:chunk文件服務器(文件存放服務器)
文件介紹的也是使用moosefs,官方網站:http://www.moosefs.org/reference-guide.html#making-and-installing
裏面有篇中文文檔,挺靠譜的。
3.1 PA安裝MooseFS Master
wget http://ncu.dl.sourceforge.net/project/moosefs/moosefs/1.6.11/mfs-1.6.11.tar.gz tar zxvf mfs-1.6.11.tar.gz cd mfs-1.6.11 useradd mfs -s /sbin/nologin ./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs make make install
把Master配置文件,拷貝過去:
cd /usr/local/mfs/etc/ cp mfsmaster.cfg.dist mfsmaster.cfg cp mfsexports.cfg.dist mfsexports.cfg
啓動、暫停命令
/usr/local/mfs/sbin/mfsmaster start
/usr/local/mfs/sbin/mfsmaster –s
Master mfsexports.cfg配置
192.168.2.0/24 . rw
192.168.2.0/24 / rw
設置副本的份數,推薦 3 份
/usr/local/mfs/bin/mfssetgoal -r 3
3.2 P一、P二、P3安裝MooseFS Chunk Server
wget http://ncu.dl.sourceforge.net/project/moosefs/moosefs/1.6.11/mfs-1.6.11.tar.gz tar zxvf mfs-1.6.11.tar.gz cd mfs-1.6.11 useradd mfs -s /sbin/nologin ./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs make make install
把Chunk Server配置文件,拷貝過去:
cd /usr/local/mfs/etc/ cp mfschunkserver.cfg.dist mfschunkserver.cfg cp mfshdd.cfg.dist mfshdd.cfg
啓動、暫停命令
/usr/local/mfs/sbin/mfschunkserver start
/usr/local/mfs/sbin/mfschunkserver stop
mfshdd.cfg配置
/data/mfs #文件存放路徑
3.3 MooseFS Client安裝
PA、P一、P二、P3都安裝,安裝以下:
wget http://ncu.dl.sourceforge.net/project/moosefs/moosefs/1.6.11/mfs-1.6.11.tar.gz tar zxvf mfs-1.6.11.tar.gz cd mfs-1.6.11 useradd mfs -s /sbin/nologin ./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs --enable-mfsmount make make install
PA、P一、P二、P3掛載文件系統:
/usr/local/mfs/bin/mfsmount /storage -H 192.168.2.2
總結: 好了,三種解決方案都介紹完了,總體都很簡單,趕快來選擇適合本身的解決方案吧,動手試試吧!
固然三種方案都有本身的優缺點,我但願看了文章的不點推薦的人就回答下這些問題吧!