How to deploy JuiceFS

JuiceFS is quite easy to deploy with the following steps:

  1. Create a file system in juicefs web console
  2. Download juicefs command line tool
  3. Mount juicefs file system

You may do it manually following the Getting Started guide.

Alternatively, you may automate it with DevOps tools such as Ansible, Salt and etc.

Manual

Use the following command to download and mount JuiceFS.

curl -L juicefs.com/static/juicefs -o juicefs && chmod +x juicefs
sudo ./juicefs auth --token $JFS_TOKEN --accesskey $ACCESSKEY --secretkey $SECRETKEY $JFS_NAME
sudo ./juicefs mount $JFS_NAME $JFS_MOUNTPONT

Add a line to /etc/fstab so that it will be mounted automatically after booting. For example:

JFS_NAME  /jfs     juicefs    _netdev   0 0

Note

By default, CentOS 6 will NOT mount network filesystem after boot, run sudo chkconfig --add netfs to enable it.

Using Shell Script

#!/bin/sh
cd /tmp
curl -L juicefs.com/static/juicefs -o juicefs && chmod +x juicefs
sudo ./juicefs auth "$1" --token "$2" --accesskey "$3" --secretkey "$4"
sudo ./juicefs mount "$1" "$5"

Save the above content as a shell script setup-juicefs.sh and mount JuiceFS with one-line command:

./setup-juicefs.sh $JFS_NAME $JFS_TOKEN $ACCESSKEY $SECRETKEY $JFS_MOUNTPONT

Note

For environment that does not require accesskey or secretkey, e.g. using AWS IAM role for authentication, put a placeholder '' for the corresponding arguments.

Using Salt

Example state snippets to deploy JuiceFS with Salt.

/root/juicefs:
    file.managed:
        - source: https://juicefs.com/static/juicefs
        - mode:  0755
        - skip_verify: True

juicefs auth:
    cmd.run:
        - name: /root/juicefs auth {{jfs_name}} --token {{jfs_token}} --accesskey={{accesskey}} --secretkey={{secretkey}}
        - creates: /root/.juicefs/{{jfs_name}}.conf
    require:
        - file: /root/juicefs

/jfs:
    mount.mounted:
        - device: {{jfs_name}}
        - fstype: juicefs
        - mkmnt: True
        - opts: _netdev
        - device_name_regex:
            - JuiceFS:{{jfs_name}}
    require:
        - cmd: juicefs auth

Note

juicefs command line tool will automatically add prefix JuiceFS: to the device name. Therefore, you need to apply a regex match for it.

Using Ansible

Example for mounting JuiceFS on localhost using Ansible playbook

- hosts: localhost
  tasks:
    - set_fact:
        jfs_bin: /usr/local/bin/juicefs

    - get_url:
        url: https://juicefs.com/static/juicefs
        mode: 0755
        dest: "{{jfs_bin}}

    - command: {{jfs_bin}} auth {{jfs_name}} --token {{jfs_token}} --accesskey={{accesskey}} --secretkey={{secretkey}}
      args:
        creates: /root/.juicefs/{{jfs_name}}.conf

    - mount:
        path: "{{jfs_path}}"
        src: "{{jfs_name}}"
        fstype: juicefs
        opts: _netdev
        state: mounted