ZFS安装配置
参考链接:https://github.com/zfsonlinux/zfs/wiki/RHEL-and-CentOS
参考链接:https://docs.oracle.com/cd/E24847_01/html/819-7065/docinfo.html#scrolltoc
一、安装ZFS
1. AWS EC2镜像如下:
2. 安装yum源
#yum install -y http://download.zfsonlinux.org/epel/zfs-release.el6.noarch.rpm
#gpg --quiet --with-fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux
备注说明:
After installing the zfs-release package and verifying the public key users can opt to install ether the kABI-tracking kmod or DKMS style packages. For most users the kABI-tracking kmod packages are recommended in order to avoid needing to rebuild ZFS for every kernel update. DKMS packages are recommended for users running a non-distribution kernel or for users who wish to apply local customizations to ZFS on Linux.
注意:3和4选择一种方法安装即可,此处选择3
3. 使用kmod安装
(1)修改zfs.repo
#vi /etc/yum.repos.d/zfs.repo
[zfs]
name=ZFS on Linux for EL 7 - dkms
baseurl=http://download.zfsonlinux.org/epel/7/$basearch/
-enabled=1
+enabled=0
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux
@@ -9,7 +9,7 @@
[zfs-kmod]
name=ZFS on Linux for EL 7 - kmod
baseurl=http://download.zfsonlinux.org/epel/7/kmod/$basearch/
-enabled=0
+enabled=1
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux
(2)安装zfs
#yum install –y zfs
(3)加载内核
#modprobe zfs
4. DKMS安装
#yum install –y epel-release
#yum install –y "kernel-devel-uname-r == $(uname -r)" zfs
#modprobe zfs
二、创建zfspool
1. 创建存储池
#zpool create <poolname> <device>
示例:zpool create mypool xvdf
示例raidz1:zpool create mypool raidz1 xvdb xvdc xvdd xvde xvdg xvdh
示例:挂载 zfs mount -a
三、配置NFS
1. 安装nfs
#yum install –y nfs-utils rpcbind
#service rpcbind start
#service nfs start
#service nfslock start
#chkconfig rpcbind on
#chkconfig nfs on
#chkconfig nfslock on
2. 开启NFS共享
#zfs sharenfs=on mypool
3. 配置nfs
#zfs set sharenfs=’rw=@0.0.0.0/0’ mypool
4. 启动共享
#zfs share –a
5. 查看共享
#showmount –e localhost
6. 查看监听端口
#rpcinfo –p
四、zfs扩容
示例:zpool add mypool raidz1 xvdb xvdc xvdd xvde xvdf xvdg xvdh
五、zfs快照
#zfs snapshot poolname@snapshotname
示例:zfs snapshot -r mypool@snapshot-`date '+%F-%H-%M-%S'`-`date +%s`
注:如果有子zfs文件系统,需要加-r递归创建快照
六、zfs设置容量限制
#zfs set quota=20T mypool/myfs1
七、zfswatcher安装
参考链接:http://zfswatcher.damicon.fi/
1. 下载
#wget http://zfswatcher.damicon.fi/dist/zfswatcher-0.03-1.x86_64.rpm
2. 安装
#yum install -y zfswatcher-0.03-1.x86_64.rpm
3. 修改配置文件
#vim /etc/zfs/zfswatcher.conf
4. 修改 [www] 模块
enable改为true
bind 改为 可用端口,如80,8080等
修改 [wwwuser “root”] 模块
password 设置密码,需要使用zfswatcher -P生成hash值
5. 启动服务
#service zfswatcher restart
6. iptables、安全组放行
7. 访问
http://ip:port
用户名:root
密码:输入设置的密码
八、ZFS快照脚本
#!/bin/bash
#create and delete zfs snapshot for /mypool
cd /root/shell
#timestamp for delete snapshot
time0=$((`date +%s`-21600))
#create snapshot for mypool
/sbin/zfs snapshot -r mypool@snapshot-`date '+%F-%H-%M-%S'`-`date +%s`
#delete snapshot >6h
/sbin/zfs list -t snapshot mypool -r |grep "@"|awk '{print $1}' >delete_list1
cat delete_list1 | while read line
do
time1=`echo $line|awk -F- '{print $(NF)}'`
[[ ${time1} -lt ${time0} ]]&&/sbin/zfs destroy $line
done
——本文作者:赵毅鹏,沈磊