Install ZFS on CentOS use yum

本文介绍如何在CentOS 6.x中安装带有DKMS支持的ZFS文件系统,包括从官方源安装所需的软件包及配置服务自启动的方法。此外,还提供了在特定网络环境下对安装包进行重命名的建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用打包好的安装, 好处是加了dkms支持. 一些配置也都弄好了.

以centos 6.x为例
需要访问外网.
$ sudo yum localinstall --nogpgcheck http://archive.zfsonlinux.org/epel/zfs-release$(rpm -E %dist).noarch.rpm
$ sudo yum install zfs 

如果你的机子仅仅只能临时出外网的话,  用完建议重命名.
下次要用的时候, 先申请出外网的权限再把它改回去.
[root@db- ~]# cd /etc/yum.repos.d/
[root@db- yum.repos.d]# ll
total 16
-rw-r--r--. 1 root root 2081 Mar 14 14:27 CentOS6-Base-skymobi_San_Dun.repo
-rw-r--r--. 1 root root 1109 Mar 14 14:27 epel6-skymobi_San_Dun.repo
drwxr-xr-x  2 root root 4096 Mar 14 14:30 repos_back
-rw-r--r--  1 root root  771 May 31 05:14 zfs.repo
[root@db- yum.repos.d]# mv zfs.repo zfs.repo.bak

使用yum安装的话, 自动添加init.d服务.
[root@db-172-16-3-150 src]# chkconfig --list|grep zfs
zfs             0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@db-172-16-3-150 src]# cat /etc/init.d/zfs
#!/bin/bash
#
# zfs           This script will mount/umount the zfs filesystems.
#
# chkconfig:    2345 01 99
# description:  This script will mount/umount the zfs filesystems during
#               system boot/shutdown.  Configuration of which filesystems
#               should be mounted is handled by the zfs 'mountpoint' and
#               'canmount' properties.  See the zfs(8) man page for details.
#               It is also responsible for all userspace zfs services.
#
### BEGIN INIT INFO
# Provides: zfs
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: Mount/umount the zfs filesystems
# Description: ZFS is an advanced filesystem designed to simplify managing
#              and protecting your data.  This service mounts the ZFS
#              filesystems and starts all related zfs services.
### END INIT INFO

export PATH=/usr/local/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin

if [ -z "$init" ]; then
    # Not interactive
    grep -Eqi 'zfs=off|zfs=no' /proc/cmdline && exit 3
fi

# Source function library & LSB routines
. /etc/rc.d/init.d/functions

# script variables
RETVAL=0
ZFS="/sbin/zfs"
ZPOOL="/sbin/zpool"
ZPOOL_CACHE="/etc/zfs/zpool.cache"
servicename=zfs
LOCKFILE=/var/lock/subsys/$servicename

# functions
zfs_installed() {
        modinfo zfs > /dev/null 2>&1 || return 5
        $ZPOOL  > /dev/null 2>&1
        [ $? == 127 ] && return 5
        $ZFS    > /dev/null 2>&1
        [ $? == 127 ] && return 5
        return 0
}

# i need a bash guru to simplify this, since this is copy and paste, but donno how
# to correctly dereference variable names in bash, or how to do this right

# first parameter is a regular expression that filters fstab
read_fstab() {
        unset FSTAB
        n=0
        while read -r fs mntpnt fstype opts blah ; do
                fs=`printf '%b\n' "$fs"`
                FSTAB[$n]=$fs
                let n++
        done < <(egrep "$1" /etc/fstab)
}

start()
{
        # Disable lockfile check
        # if [ -f "$LOCKFILE" ] ; then return 0 ; fi

        # check if ZFS is installed.  If not, comply to FC standards and bail
        zfs_installed || {
                action $"Checking if ZFS is installed: not installed" /bin/false
                return 5
        }

        # Requires selinux policy which has not been written.
        if [ -r "/selinux/enforce" ] &&
           [ "$(cat /selinux/enforce)" = "1" ]; then
                action $"SELinux ZFS policy required: " /bin/false || return 6
        fi

        # Delay until all required block devices are present.
        if [ -x /sbin/udevadm ]; then
                /sbin/udevadm settle
        elif [ -x /sbin/udevsettle ]; then
                /sbin/udevsettle
        fi

        # load kernel module infrastructure
        if ! grep -q zfs /proc/modules ; then
                action $"Loading kernel ZFS infrastructure: " modprobe zfs || return 5
        fi
        sleep 1

        action $"Mounting automounted ZFS filesystems: " $ZFS mount -a || return 152

        action $"Exporting ZFS filesystems: " $ZFS share -a || return 153

        # Read fstab, try to mount zvols ignoring error
        read_fstab "^/dev/(zd|zvol)"
        template=$"Mounting volume %s registered in fstab: "
        for volume in "${FSTAB[@]}" ; do
                string=`printf "$template" "$volume"`
                action "$string" mount "$volume" 2>/dev/null || /bin/true
        done

        # touch "$LOCKFILE"
}

stop()
{
        # Disable lockfile check
        # if [ ! -f "$LOCKFILE" ] ; then return 0 ; fi

        # check if ZFS is installed.  If not, comply to FC standards and bail
        zfs_installed || {
                action $"Checking if ZFS is installed: not installed" /bin/false
                return 5
        }

        # the poweroff of the system takes care of this
        # but it never unmounts the root filesystem itself
        # shit

        action $"Syncing ZFS filesystems: " sync
             # about the only thing we can do, and then we
             # hope that the umount process will succeed
             # unfortunately the umount process does not dismount
             # the root file system, there ought to be some way
             # we can tell zfs to just flush anything in memory
             # when a request to remount,ro comes in

        #echo -n $"Unmounting ZFS filesystems: "
        #$ZFS umount -a
        #RETVAL=$?
        #if [ $RETVAL -ne 0 ]; then
        #       failure

        #       return 8
        #fi
        #success

        rm -f "$LOCKFILE"
}

# See how we are called
case "$1" in
        start)
                start
                RETVAL=$?
                ;;
        stop)
                stop
                RETVAL=$?
                ;;
        status)
                lsmod | grep -q zfs || RETVAL=3
                $ZPOOL status && echo && $ZFS list || {
                        [ -f "$LOCKFILE" ] && RETVAL=2 || RETVAL=4
                }
                ;;
        restart)
                stop
                start
                ;;
        condrestart)
                if [ -f "$LOCKFILE" ] ; then
                        stop
                        start
                fi
                ;;
        *)
                echo $"Usage: $0 {start|stop|status|restart|condrestart}"
                RETVAL=3
                ;;
esac

exit $RETVAL

[参考]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值