在CENTOS6上面,需要安裝mysql數據庫,爲提高數據庫的讀寫效率和性能,準備將mysql數據文件系統安裝在XFS分區上。
XFS,一種高性能的日誌文件系統,最早於1993年,由Silicon Graphics爲他們的IRIX操作系統而開發,是IRIX 5.3版的默認文件系統。後來被移植到Linux 內核上。XFS 特別擅長處理大文件,同時提供平滑的數據傳輸。在存儲很大的環境下進行格式化操作,XFS文件系統的速度比ext3、ext4文件系統快了很多!而且據說XFS可以支持到100T,讀寫速度也優於其他文件系統。
系統環境:CENTOS6.4
一、安裝xfs文件系統
XFS所需要的rpm包在系統的ISO文件中都可以找到,我們只需要安裝xfsprogs和xfsdump這兩個包就可以了。
[root@localhost Packages]# find . -name "xfs*.rpm"
./xfsdump-3.0.4-3.el6.x86_64.rpm
./xfsprogs-devel-3.1.1-10.el6.x86_64.rpm
./xfsprogs-qa-devel-3.1.1-10.el6.i686.rpm
./xfsprogs-qa-devel-3.1.1-10.el6.x86_64.rpm
./xfsprogs-devel-3.1.1-10.el6.i686.rpm
./xfsprogs-3.1.1-10.el6.i686.rpm
./xfsprogs-3.1.1-10.el6.x86_64.rpm
[root@localhost Packages]# rpm -ivh xfsprogs-3.1.1-10.el6.x86_64.rpm xfsdump-3.0.4-3.el6.x86_64.rpm
warning: xfsprogs-3.1.1-10.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:xfsprogs ########################################### [ 50%]
2:xfsdump ########################################### [100%]
二、XFS格式化
XFS格式化速度很快,幾乎是立刻就完成了格式化。
[root@localhost Packages]# mkfs.xfs /dev/sdb
meta-data=/dev/sdb isize=256 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
三、掛載測試
[root@localhost /]# mount -t xfs /dev/sdb /data
[root@localhost /]# mount |grep data
/dev/sdb on /data type xfs (rw)
測試:
寫性能
[root@localhost test]# time dd if=/dev/zero of=/data/test/ceshi.txt bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.42419 s, 247 MB/s
real0m0.431s
user0m0.001s
sys0m0.427s
讀性能
[root@localhost test]# time dd if=/data/test/ceshi.txt of=/dev/null bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.129903 s, 807 MB/s
real0m0.135s
user0m0.003s
sys0m0.132s
四、補充XFS優化
#mkfs.xfs -f -i size=512 -l size=128m,lazy-count=1 -d agcount=16 /dev/sdb1
-i size=512 : 默認的值是256KB,這裏的設置是爲了selinux的,這個設置針對inode size,selinux使用xfs的Extend Attribute,首先要寫到inode中,如果容量不夠(默認是256KB的時候就不夠,剛剛多一點點),就寫到block中,這會損失性能,當需要使用selinux的時候。這似乎對一般用戶沒什麼作用,因爲一般用戶都不用selinux的,大家對linux系統的安全性還是挺信任的,不過,說實話,我不信任,況且RedHat 的FC已經默認配置了selinux,這很好。做了這個改動,方便以後我在系統中配置selinux而不擔心性能的損失。
-l size=128m :注意是小寫的m,不是大寫的。默認值的是10m(bsize=4096 x blocks=2560)。這個值可以設置成32m(分區容量不小於250M)/64m(分區容量不小於500M)/128m(分區容量不小於700M),對於分區容量的限制,我這裏列出的只是大概,最大可設128m。修改這個參數成128m,可以顯著的提高xfs文件系統刪除文件的速度,當然還有其它,如拷貝文件的速度。 這個參數需要大內存的支持,內存太少的機器大概不能設置這麼高。(標準是什麼?512M?1G?我不瞭解,所以我上面說要自己實際的測試一下。)
-l lazy-count=value
This changes the method of logging various persistent counters in the superblock. Under metadata intensive workloads, these counters are updated and logged frequently enough that the superblock updates become a serialisation point in the filesystem. The value can be either 0 or 1.
With lazy-count=1, the superblock is not modified or logged on every change of the persis-tent counters. Instead, enough information is kept in other parts of the filesystem to be able to maintain the persistent counter values without needed to keep them in the superblock. This gives significant improvements in performance on some configurations. The default value is 0 (off) so you must specify lazy-count=1 if you want to make use of this feature.
-d agcount=4 :默認值是根據容量自動設置的。可以設置成1/2/4/16等等,這個參數可以調節對CPU的佔用率,值越小,佔用率越低。這是理論上的,在我的機器上,agcount=1反而比agcount=2的cpu佔用率還高,我想這是因爲我的cpu是雙核的原因吧。要注意,cpu的佔用率低,那每一秒處理的數據量也會降低一些。我比較了agcount=2和4,發現還是4比較好。這樣一來,這個參數的設置,就是需要自己去選擇的了。
mount的xfs選項(關鍵參數nobarrier):
vi /etc/fstab
修改掛載選項
/dev/sdb1 /data xfs defaults,noatime,nobarrier 00
重新掛載
mount -o remount /data
nobarrier
Many hardware RAID have a persistent write cache which preserves it across power failure, interface resets, system crashes, etc. Using write barriers in this instance is not recommended and will in fact lower performance. Therefore, it is recommended to turn off the barrier support and mount the filesystem with "nobarrier". But take care about the hard disk write cache, which should be off.
noatime 默認的方式下linux會把文件訪問的時間atime做記錄,這在絕大部分的場合都是沒有必要的,如果遇到機器IO負載高或是CPU WAIT高的情況,可以嘗試使用noatime,療效好,見效快。
nobarrier掛載
logbufs=value
Set the number of in-memory log buffers. Valid numbers range from 2-8 inclusive. The default value is 8 buffers for filesystems with a blocksize of 64K, 4 buffers for filesystems with a blocksize of 32K, 3 buffers for filesystems with a blocksize of 16K, and 2 buffers for all other configurations. Increasing the number of buffers may increase performance on some workloads at the cost of the memory used for the additional log buffers and their associated control structures.
logbsize=value
Set the size of each in-memory log buffer. Valid sizes are 16384 (16K) and 32768 (32K). The default value for machines with more than 32MB of memory is 32768, machines with less memory use 16384 by default.
測試後發現讀寫性能還可以更好,測試方法同上。
五、XFS的優缺點
優點:
XFS使用高的表結構(B+樹),保證了文件系統可以快速搜索與快速空間分配。XFS能夠持續提供高速操作,文件系統的性能不受目錄中目錄及文件數量的限制。
注:一般大於2T的分區用PARTED來分,而對於大於16T的分區雖然可以用PARTED來分,但使用EXT4分區格式來掛載時,也易出錯。在這個時候把大於16T的單個分區用XFS來格式化,然後掛載是可以正常的。
XFS 能以接近裸設備I/O的性能存儲數據。在單個文件系統的測試中,其吞吐量最高可達7GB每秒,對單個文件的讀寫操作,其吞吐量可達4GB每秒
缺點: