add ansible installation with mnmd (#664)

* add ansible installation with mnmd

* change script install dir name
This commit is contained in:
majinghe
2025-10-18 22:20:17 +08:00
committed by GitHub
parent 4168e6c180
commit 95019c4cb5
3 changed files with 389 additions and 0 deletions

106
docs/ansible/REAEME.md Normal file
View File

@@ -0,0 +1,106 @@
# Install rustfs with mnmd mode using ansible
This chapter show how to install rustfs with mnmd(multiple nodes multiple disks) using ansible playbook.Two installation method are available, namely binary and docker compose.
## Requirments
- Multiple nodes(At least 4 nodes,each has private IP and public IP)
- Multiple disks(At least 1 disk per nodes, 4 disks is a better choice)
- Ansible should be avialable
- Docker should be available(only for docker compose installation)
## Binary installation and uninstallation
### Installation
For binary installation([script installation](https://rustfs.com/en/download/),you should modify the below part of the playbook,
```
- name: Modify Target Server's hosts file
blockinfile:
path: /etc/hosts
block: |
172.92.20.199 rustfs-node1
172.92.20.200 rustfs-node2
172.92.20.201 rustfs-node3
172.92.20.202 rustfs-node4
```
Replacing the IP with your nodes' **private IP**.If you have more than 4 nodes, adding the ip in order.
Runing the command to install rustfs
```
ansible-playbook --skip-tags rustfs_uninstall binary-mnmd.yml
```
After installation success, you can access the rustfs cluster via any node's public ip and 9000 port. Both default username and password are `rustfsadmin`.
### Uninstallation
Running the command to uninstall rustfs
```
ansible-playbook --tags rustfs_uninstall binary-mnmd.yml
```
## Docker compose installation and uninstallation
**NOTE**: For docker compose installation,playbook contains docker installation task,
```
tasks:
- name: Install docker
shell: |
apt-get remove -y docker docker.io containerd runc || true
apt-get update -y
apt-get install -y ca-certificates curl gnupg lsb-release
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update -y
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
become: yes
register: docker_installation_result
changed_when: false
- name: Installation check
debug:
var: docker_installation_result.stdout
```
If your node already has docker environment,you can add `tags` in the playbook and skip this task in the follow installation.By the way, the docker installation only for `Ubuntu` OS,if you have the different OS,you should modify this task as well.
For docker compose installation,you should also modify the below part of the playbook,
```
extra_hosts:
- "rustfs-node1:172.20.92.202"
- "rustfs-node2:172.20.92.201"
- "rustfs-node3:172.20.92.200"
- "rustfs-node4:172.20.92.199"
```
Replacing the IP with your nodes' **private IP**.If you have more than 4 nodes, adding the ip in order.
Running the command to install rustfs,
```
ansible-playbook --skip-tags docker_uninstall docker-compose-mnmd.yml
```
After installation success, you can access the rustfs cluster via any node's public ip and 9000 port. Both default username and password are `rustfsadmin`.
### Uninstallation
Running the command to uninstall rustfs
```
ansible-playbook --tags docker_uninstall docker-compose-mnmd.yml
```

View File

@@ -0,0 +1,168 @@
---
- name: Prepare for RustFS installation
hosts: rustfs
become: yes
vars:
ansible_python_interpreter: /usr/bin/python3
remote_user: root
tasks:
- name: Create Workspace
file:
path: /opt/rustfs
state: directory
mode: '0755'
register: create_dir_result
- name: Dir Creation Result Check
debug:
msg: "RustFS dir created successfully"
when: create_dir_result.changed
- name: Modify Target Server's hosts file
blockinfile:
path: /etc/hosts
block: |
127.0.0.1 localhost
172.20.92.199 rustfs-node1
172.20.92.200 rustfs-node2
172.20.92.201 rustfs-node3
172.20.92.202 rustfs-node4
- name: Create rustfs group
group:
name: rustfs
system: yes
state: present
- name: Create rustfs user
user:
name: rustfs
shell: /bin/bash
system: yes
create_home: no
group: rustfs
state: present
- name: Get rustfs user id
command: id -u rustfs
register: rustfs_uid
changed_when: false
ignore_errors: yes
- name: Check rustfs user id
debug:
msg: "rustfs uid is {{ rustfs_uid.stdout }}"
- name: Create volume dir
file:
path: "{{ item }}"
state: directory
owner: rustfs
group: rustfs
mode: '0755'
loop:
- /data/rustfs0
- /data/rustfs1
- /data/rustfs2
- /data/rustfs3
- /var/logs/rustfs
- name: Install RustFS
hosts: rustfs
become: yes
vars:
ansible_python_interpreter: /usr/bin/python3
install_script_url: "https://rustfs.com/install_rustfs.sh"
install_script_tmp: "/opt/rustfs/install_rustfs.sh"
tags: rustfs_install
tasks:
- name: Prepare configuration file
copy:
dest: /etc/default/rustfs
content: |
RUSTFS_ACCESS_KEY=rustfsadmin
RUSTFS_SECRET_KEY=rustfsadmin
RUSTFS_VOLUMES="http://rustfs-node{1...4}:9000/data/rustfs{0...3}"
RUSTFS_ADDRESS=":9000"
RUSTFS_CONSOLE_ENABLE=true
RUST_LOG=error
RUSTFS_OBS_LOG_DIRECTORY="/var/logs/rustfs/"
RUSTFS_EXTERNAL_ADDRESS=0.0.0.0:9000
owner: root
group: root
mode: '0644'
- name: Install unzip
apt:
name: unzip
state: present
update_cache: yes
- name: Download the rustfs install script
get_url:
url: "{{ install_script_url }}"
dest: "{{ install_script_tmp }}"
mode: '0755'
- name: Run rustfs installation script
expect:
command: bash "{{install_script_tmp}}"
responses:
'.*Enter your choice.*': "1\n"
'.*Please enter RustFS service port.*': "9000\n"
'.*Please enter RustFS console port.*': "9001\n"
'.*Please enter data storage directory.*': "http://rustfs-node{1...4}:9000/data/rustfs{0...3}\n"
timeout: 300
register: rustfs_install_result
tags:
- rustfs_install
- name: Debug installation output
debug:
var: rustfs_install_result.stdout_lines
- name: Installation confirmation
command: rustfs --version
register: rustfs_version
changed_when: false
failed_when: rustfs_version.rc != 0
- name: Show rustfs version
debug:
msg: "RustFS version is {{ rustfs_version.stdout }}"
- name: Uninstall RustFS
hosts: rustfs
become: yes
vars:
install_script_tmp: /opt/rustfs/install_rustfs.sh
ansible_python_interpreter: /usr/bin/python3
tags: rustfs_uninstall
tasks:
- name: Run rustfs uninstall script
expect:
command: bash "{{ install_script_tmp }}"
responses:
'Enter your choice.*': "2\n"
'Are you sure you want to uninstall RustFS.*': "y\n"
timeout: 300
register: rustfs_uninstall_result
tags: rustfs_uninstall
- name: Debug uninstall output
debug:
var: rustfs_uninstall_result.stdout_lines
- name: Delete data dir
file:
path: "{{ item }}"
state: absent
loop:
- /data/rustfs0
- /data/rustfs1
- /data/rustfs2
- /data/rustfs3
- /var/logs/rustfs

View File

@@ -0,0 +1,115 @@
---
- name: Prepare for RustFS installation
hosts: rustfs
become: yes
vars:
ansible_python_interpreter: /usr/bin/python3
install_script_url: "https://rustfs.com/install_rustfs.sh"
docker_compose: "/opt/rustfs/docker-compose"
remote_user: root
tasks:
- name: Install docker
tags: docker_install
shell: |
apt-get remove -y docker docker.io containerd runc || true
apt-get update -y
apt-get install -y ca-certificates curl gnupg lsb-release
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update -y
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
become: yes
register: docker_installation_result
changed_when: false
when: ansible_facts['distribution'] == "Ubuntu"
- name: Installation check
debug:
var: docker_installation_result.stdout
when: ansible_facts['distribution'] == "Ubuntu"
- name: Create docker compose dir
file:
path: "{{ docker_compose }}"
state: directory
mode: '0755'
- name: Prepare docker compose file
copy:
content: |
services:
rustfs:
image: rustfs/rustfs:latest
container_name: rustfs
hostname: rustfs
network_mode: host
environment:
# Use service names and correct disk indexing (1..4 to match mounted paths)
- RUSTFS_VOLUMES=http://rustfs-node{1...4}:9000/data/rustfs{1...4}
- RUSTFS_ADDRESS=0.0.0.0:9000
- RUSTFS_CONSOLE_ENABLE=true
- RUSTFS_CONSOLE_ADDRESS=0.0.0.0:9001
- RUSTFS_EXTERNAL_ADDRESS=0.0.0.0:9000 # Same as internal since no port mapping
- RUSTFS_ACCESS_KEY=rustfsadmin
- RUSTFS_SECRET_KEY=rustfsadmin
- RUSTFS_CMD=rustfs
command: ["sh", "-c", "sleep 3 && rustfs"]
healthcheck:
test:
[
"CMD-SHELL",
"curl -f http://localhost:9000/health && curl -f http://localhost:9001/health || exit 1"
]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
ports:
- "9000:9000" # API endpoint
- "9001:9001" # Console
volumes:
- rustfs-data1:/data/rustfs1
- rustfs-data2:/data/rustfs2
- rustfs-data3:/data/rustfs3
- rustfs-data4:/data/rustfs4
extra_hosts:
- "rustfs-node1:172.20.92.202"
- "rustfs-node2:172.20.92.201"
- "rustfs-node3:172.20.92.200"
- "rustfs-node4:172.20.92.199"
volumes:
rustfs-data1:
rustfs-data2:
rustfs-data3:
rustfs-data4:
dest: "{{ docker_compose }}/docker-compose.yml"
mode: '0644'
- name: Install rustfs using docker compose
tags: rustfs_install
command: docker compose -f "{{ docker_compose}}/docker-compose.yml" up -d
args:
chdir: "{{ docker_compose }}"
- name: Get docker compose output
command: docker compose ps
args:
chdir: "{{ docker_compose }}"
register: docker_compose_output
- name: Check the docker compose installation output
debug:
msg: "{{ docker_compose_output.stdout }}"
- name: Uninstall rustfs using docker compose
tags: rustfs_uninstall
command: docker compose -f "{{ docker_compose}}/docker-compose.yml" down
args:
chdir: "{{ docker_compose }}"