Skip to main content

Automation Deployment

After JuiceFS has been successfully mounted, you can automate this process to mount JuiceFS on multiple hosts. Several different approaches are introduced in this chapter.

You'll be needing your JuiceFS Token, and credentials for object storage, use them to run juicefs auth to generate a config file:

sudo juicefs auth myjfs --token xxxxx --accesskey xxxxx --secretkey xxxxx

The config file generated above is /root/.juicefs/myjfs.conf, which includes crucial information like the JuiceFS Token, Volume Name, and object storage access credentials:

/root/.juicefs/myjfs.conf
{
"rootname": "myjfs",
"storage": "oss",
"region": "cn-shanghai",
"bucket": "myjfs.oss-cn-shanghai.aliyuncs.com",
"partitions": 0,
"replicated": false,
"compatible": false,
"public": false,
"blockSize": 4096,
"master": "aliyun-shanghai-1.meta.juicefs.com:9408",
"master_ip": [
"106.4.4.94",
"47.100.10.252",
"47.123.123.227"
],
"password": "xxxxx",
"compress": "lz4",
"accesskey": "xxxxx",
"secretkey": "xxxxx",
"tested": 1,
"token": "xxxxx"
}

Shell Script

Create a simple bash script, e.g. setup-juicefs.sh:

setup-juicefs.sh
#!/bin/sh
set -e
curl -sSL juicefs.com/static/juicefs -o /usr/local/bin/juicefs && chmod +x /usr/local/bin/juicefs
sudo juicefs auth "$1" --token "$2" --accesskey "$3" --secretkey "$4"
sudo juicefs mount "$1" "$5"

And then mount can be done without interaction by using the following command:

./setup-juicefs.sh $VOL_NAME $JFS_TOKEN $ACCESSKEY $SECRETKEY $JFS_MOUNTPONT
tip

If your cloud service provider supports configuring bucket access policy for virtual machines, and achieve access to object storage without credentials (like AWS IAM), you can omit those keys during juicefs auth or juicefs mount (provide empty value), see juicefs auth for details.

SaltStack

Use below example to deploy JuiceFS with SaltStack:

/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
# JuiceFS storage name is prefixed with JuiceFS:
- device_name_regex:
- JuiceFS:{{jfs_name}}
require:
- cmd: juicefs auth

Ansible

Use below example to deploy JuiceFS with Ansible:

- hosts: localhost
tasks:
- set_fact:
# Change accordingly
jfs_bin: /usr/local/bin/juicefs
jfs_path: /jfs
jfs_name: jfs-volume
jfs_token: xxx
accesskey: xxx
secretkey: xxx

- 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

- name: Create symbolic for fstab
ansible.builtin.file:
src: "{{jfs_bin}}"
dest: "/sbin/mount.juicefs"
state: link

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