debian-mirror-gitlab/doc/administration/high_availability/nfs_host_client_setup.md

153 lines
6 KiB
Markdown
Raw Normal View History

2019-09-30 21:07:59 +05:30
---
type: reference
---
2019-07-31 22:56:46 +05:30
# Configuring NFS for GitLab HA
Setting up NFS for a GitLab HA setup allows all applications nodes in a cluster
to share the same files and maintain data consistency. Application nodes in an HA
setup act as clients while the NFS server plays host.
> Note: The instructions provided in this documentation allow for setting a quick
proof of concept but will leave NFS as potential single point of failure and
therefore not recommended for use in production. Explore options such as [Pacemaker
2019-12-21 20:55:43 +05:30
and Corosync](https://clusterlabs.org) for highly available NFS in production.
2019-07-31 22:56:46 +05:30
Below are instructions for setting up an application node(client) in an HA cluster
to read from and write to a central NFS server(host).
NOTE: **Note:**
Using EFS may negatively impact performance. Please review the [relevant documentation](nfs.md#avoid-using-awss-elastic-file-system-efs) for additional details.
## NFS Server Setup
> Follow the instructions below to set up and configure your NFS server.
### Step 1 - Install NFS Server on Host
2020-04-08 14:13:33 +05:30
Installing the `nfs-kernel-server` package allows you to share directories with the clients running the GitLab application.
2019-07-31 22:56:46 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-07-31 22:56:46 +05:30
apt-get update
apt-get install nfs-kernel-server
```
### Step 2 - Export Host's Home Directory to Client
In this setup we will share the home directory on the host with the client. Edit the exports file as below to share the host's home directory with the client. If you have multiple clients running GitLab you must enter the client IP addresses in line in the `/etc/exports` file.
2020-05-24 23:13:21 +05:30
```plaintext
2019-07-31 22:56:46 +05:30
#/etc/exports for one client
/home <client-ip-address>(rw,sync,no_root_squash,no_subtree_check)
#/etc/exports for three clients
/home <client-ip-address>(rw,sync,no_root_squash,no_subtree_check) <client-2-ip-address>(rw,sync,no_root_squash,no_subtree_check) <client-3-ip-address>(rw,sync,no_root_squash,no_subtree_check)
```
Restart the NFS server after making changes to the `exports` file for the changes
to take effect.
2020-03-13 15:44:24 +05:30
```shell
2019-07-31 22:56:46 +05:30
systemctl restart nfs-kernel-server
```
NOTE: **Note:**
You may need to update your server's firewall. See the [firewall section](#nfs-in-a-firewalled-environment) at the end of this guide.
## Client/ GitLab application node Setup
2019-12-21 20:55:43 +05:30
> Follow the instructions below to connect any GitLab Rails application node running
2019-07-31 22:56:46 +05:30
inside your HA environment to the NFS server configured above.
### Step 1 - Install NFS Common on Client
2020-04-08 14:13:33 +05:30
The `nfs-common` provides NFS functionality without installing server components which
2019-07-31 22:56:46 +05:30
we don't need running on the application nodes.
2020-03-13 15:44:24 +05:30
```shell
2019-07-31 22:56:46 +05:30
apt-get update
apt-get install nfs-common
```
### Step 2 - Create Mount Points on Client
2019-09-04 21:01:54 +05:30
Create a directory on the client that we can mount the shared directory from the host.
2019-07-31 22:56:46 +05:30
Please note that if your mount point directory contains any files they will be hidden
once the remote shares are mounted. An empty/new directory on the client is recommended
for this purpose.
2020-03-13 15:44:24 +05:30
```shell
2019-07-31 22:56:46 +05:30
mkdir -p /nfs/home
```
Confirm that the mount point works by mounting it on the client and checking that
it is mounted with the command below:
2020-03-13 15:44:24 +05:30
```shell
2019-07-31 22:56:46 +05:30
mount <host_ip_address>:/home
df -h
```
### Step 3 - Set up Automatic Mounts on Boot
Edit `/etc/fstab` on client as below to mount the remote shares automatically at boot.
Note that GitLab requires advisory file locking, which is only supported natively in
NFS version 4. NFSv3 also supports locking as long as Linux Kernel 2.6.5+ is used.
We recommend using version 4 and do not specifically test NFSv3.
2020-04-22 19:07:51 +05:30
See [NFS documentation](nfs.md#nfs-client-mount-options) for guidance on mount options.
2019-07-31 22:56:46 +05:30
2020-05-24 23:13:21 +05:30
```plaintext
2019-07-31 22:56:46 +05:30
#/etc/fstab
2020-04-22 19:07:51 +05:30
10.0.0.1:/nfs/home /nfs/home nfs4 defaults,hard,vers=4.1,rsize=1048576,wsize=1048576,noatime,nofail,lookupcache=positive 0 2
2019-07-31 22:56:46 +05:30
```
Reboot the client and confirm that the mount point is mounted automatically.
### Step 4 - Set up GitLab to Use NFS mounts
When using the default Omnibus configuration you will need to share 5 data locations
between all GitLab cluster nodes. No other locations should be shared. Changing the
default file locations in `gitlab.rb` on the client allows you to have one main mount
point and have all the required locations as subdirectories to use the NFS mount for
2019-12-21 20:55:43 +05:30
`git-data`.
2019-07-31 22:56:46 +05:30
2020-05-24 23:13:21 +05:30
```plaintext
2019-07-31 22:56:46 +05:30
git_data_dirs({"default" => {"path" => "/nfs/home/var/opt/gitlab-data/git-data"}})
gitlab_rails['uploads_directory'] = '/nfs/home/var/opt/gitlab-data/uploads'
gitlab_rails['shared_path'] = '/nfs/home/var/opt/gitlab-data/shared'
gitlab_ci['builds_directory'] = '/nfs/home/var/opt/gitlab-data/builds'
```
Save the changes in `gitlab.rb` and run `gitlab-ctl reconfigure`.
## NFS in a Firewalled Environment
If the traffic between your NFS server and NFS client(s) is subject to port filtering
by a firewall, then you will need to reconfigure that firewall to allow NFS communication.
[This guide from TDLP](http://tldp.org/HOWTO/NFS-HOWTO/security.html#FIREWALLS)
covers the basics of using NFS in a firewalled environment. Additionally, we encourage you to
2020-04-08 14:13:33 +05:30
search for and review the specific documentation for your operating system or distribution and your firewall software.
2019-07-31 22:56:46 +05:30
Example for Ubuntu:
Check that NFS traffic from the client is allowed by the firewall on the host by running
the command: `sudo ufw status`. If it's being blocked, then you can allow traffic from a specific
client with the command below.
2020-03-13 15:44:24 +05:30
```shell
2019-07-31 22:56:46 +05:30
sudo ufw allow from <client-ip-address> to any port nfs
```
2019-09-30 21:07:59 +05:30
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
Each scenario can be a third-level heading, e.g. `### Getting error message X`.
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->