Skip to content

Commit 111534a

Browse files
bors[bot]foxycodeguimachiavelli
authored
Merge #2051
2051: Updated systemd service r=guimachiavelli a=foxycode # Pull Request ## Related issue Fixes #3243 ## What does this PR do? - added system user for meilisearch - set basic config using config file - save files to proper directories ## PR checklist Please check if your PR fulfills the following requirements: - [x] Listed the changes applied in the PR description - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Tomáš Jacík <foxycode@sunfox.cz> Co-authored-by: gui machiavelli <hey@guimachiavelli.com>
2 parents 242f575 + 9671be7 commit 111534a

File tree

1 file changed

+50
-31
lines changed

1 file changed

+50
-31
lines changed

learn/cookbooks/running_production.md

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ Using Meilisearch on your own machine for your weekend project is fun, let's agr
1212

1313
[Step 1: Install Meilisearch](/learn/cookbooks/running_production.md#step-1-install-meilisearch)
1414

15-
[Step 2: Run Meilisearch as a service](/learn/cookbooks/running_production.md#step-2-run-meilisearch-as-a-service)
15+
[Step 2: Create system user](/learn/cookbooks/running_production.md#step-2-create-system-user)
1616

17-
+ [2.1. Create a service file](/learn/cookbooks/running_production.md#_2-1-create-a-service-file)
18-
+ [2.2. Enable and start service](/learn/cookbooks/running_production.md#_2-2-enable-and-start-service)
17+
[Step 3: Create a configuration file](/learn/cookbooks/running_production.md#step-3-create-a-configuration-file)
1918

20-
[Step 3: Secure and finish your setup. Using a reverse proxy, domain name and HTTPS](/learn/cookbooks/running_production.md#step-3-secure-and-finish-your-setup-using-a-reverse-proxy-domain-name-and-https)
19+
[Step 4: Run Meilisearch as a service](/learn/cookbooks/running_production.md#step-4-run-meilisearch-as-a-service)
2120

22-
+ [3.1. Creating a reverse proxy with Nginx](/learn/cookbooks/running_production.md#_3-1-creating-a-reverse-proxy-with-nginx)
23-
+ [3.2. Set up SSL/TLS for your Meilisearch](/learn/cookbooks/running_production.md#_3-2-set-up-ssl-tls-for-your-meilisearch)
21+
+ [4.1. Create a service file](/learn/cookbooks/running_production.md#_4-1-create-a-service-file)
22+
+ [4.2. Enable and start service](/learn/cookbooks/running_production.md#_4-2-enable-and-start-service)
23+
24+
[Step 5: Secure and finish your setup](/learn/cookbooks/running_production.md#step-5-secure-and-finish-your-setup)
25+
26+
+ [5.1. Creating a reverse proxy with Nginx](/learn/cookbooks/running_production.md#_5-1-creating-a-reverse-proxy-with-nginx)
27+
+ [5.2. Set up SSL/TLS for your Meilisearch](/learn/cookbooks/running_production.md#_5-2-set-up-ssl-tls-for-your-meilisearch)
2428

2529
[Conclusion](/learn/cookbooks/running_production.md#conclusion)
2630

@@ -64,32 +68,44 @@ Meilisearch is finally installed and ready to use. To make it accessible from ev
6468

6569
```bash
6670
# Move the Meilisearch binary to your system binaries
67-
mv ./meilisearch /usr/bin/
71+
mv ./meilisearch /usr/local/bin/
6872
```
6973

70-
You can now start using Meilisearch! In your terminal, run the following command to launch meilisearch.
74+
## Step 2: Create system user
75+
76+
Running applications as root can introduce security flaws in your system. To prevent that from happening, create a dedicated system user for running Meilisearch:
7177

7278
```bash
73-
meilisearch
79+
useradd -d /var/lib/meilisearch -b /bin/false -m -r meilisearch
7480
```
7581

76-
You should see the following successful response:
82+
## Step 3: Create a configuration file
7783

84+
Download default config to `/etc`:
85+
86+
```bash
87+
wget -qO /etc/meilisearch.toml https://raw.githubusercontent.com/meilisearch/meilisearch/main/config.toml
7888
```
79-
888b d888 d8b 888 d8b 888
80-
8888b d8888 Y8P 888 Y8P 888
81-
88888b.d88888 888 888
82-
888Y88888P888 .d88b. 888 888 888 .d8888b .d88b. 8888b. 888d888 .d8888b 88888b.
83-
888 Y888P 888 d8P Y8b 888 888 888 88K d8P Y8b "88b 888P" d88P" 888 "88b
84-
888 Y8P 888 88888888 888 888 888 "Y8888b. 88888888 .d888888 888 888 888 888
85-
888 " 888 Y8b. 888 888 888 X88 Y8b. 888 888 888 Y88b. 888 888
86-
888 888 "Y8888 888 888 888 88888P' "Y8888 "Y888888 888 "Y8888P 888 888
87-
88-
Database path: "./data.ms"
89-
Server listening on: "localhost:7700"
89+
90+
Update the following lines so Meilisearch stores its data in the home folder of your newly created user:
91+
92+
```ini
93+
env = "production"
94+
master_key = "YOUR_MASTER_KEY_VALUE"
95+
db_path = "/var/lib/meilisearch/data"
96+
dump_dir = "/var/lib/meilisearch/dumps"
97+
snapshot_dir = "/var/lib/meilisearch/snapshots"
98+
```
99+
100+
Finally, create the directories you added to the configuration file and set proper privileges:
101+
102+
```bash
103+
mkdir /var/lib/meilisearch/data /var/lib/meilisearch/dumps /var/lib/meilisearch/snapshots
104+
chown -R meilisearch:meilisearch /var/lib/meilisearch
105+
chmod 750 /var/lib/meilisearch
90106
```
91107

92-
## Step 2: Run Meilisearch as a service
108+
## Step 4: Run Meilisearch as a service
93109

94110
In Linux environments, a `service` is a process that can be launched when the operating system is booting and which will keep running in the background. One of its biggest advantages is making your program available at any moment. Even if some execution problems or crashes occur, the service will be restarted and your program will be run again.
95111

@@ -99,7 +115,7 @@ If you are new to services and `systemd`, you can learn more about the basics of
99115

100116
In Debian and other Linux distributions, `systemd` allows you to create and manage your own custom services. In order to make sure that Meilisearch will always respond to your requests, you can build your own service. This way, you will ensure its availability in case of a crash or in case of system reboot. If any of these occur, `systemd` will automatically restart Meilisearch.
101117

102-
### 2.1. Create a service file
118+
### 4.1. Create a service file
103119

104120
Service files are text files that tell your operating system how to run your program, and when. They live in the `/etc/systemd/system` directory, and your system will load them at boot time. In this case, let's use a very simple service file that will run Meilisearch on port `7700`.
105121

@@ -115,10 +131,13 @@ After=systemd-user-sessions.service
115131
116132
[Service]
117133
Type=simple
118-
ExecStart=/usr/bin/meilisearch --http-addr localhost:7700 --env production --master-key Y0urVery-S3cureAp1K3y
134+
WorkingDirectory=/var/lib/meilisearch
135+
ExecStart=/usr/local/bin/meilisearch --config-file-path /etc/meilisearch.toml
136+
User=meilisearch
137+
Group=meilisearch
119138
120139
[Install]
121-
WantedBy=default.target
140+
WantedBy=multi-user.target
122141
EOF
123142
```
124143

@@ -128,7 +147,7 @@ For more information on Meilisearch security and API keys see the [security docs
128147

129148
As for now, it is not time yet to expose your Meilisearch instance to the external world. To keep running it safely inside your own environment, make it available locally at `local`. This means that only programs running on your machine are allowed to make requests to your Meilisearch instance.
130149

131-
### 2.2. Enable and start service
150+
### 4.2. Enable and start service
132151

133152
The service file you just built is all you need for creating your service. Now you must `enable` it to tell the operating system that we want it to run Meilisearch at every boot. You can then `start` the service to make it run immediately. Ensure everything is working smoothly by checking the service `status`.
134153

@@ -155,11 +174,11 @@ At this point, Meilisearch is installed and running. It is protected from eventu
155174

156175
But you probably want to open your Meilisearch to the outside world, and for now, it is isolated. Let's fix that in a safe way.
157176

158-
## Step 3: Secure and finish your setup using a reverse proxy, domain name, and HTTPS
177+
## Step 5: Secure and finish your setup
159178

160179
It's time to safely make your brand new Meilisearch available to be requested from the outside world. For this purpose, you will use two of the main technologies available on the web: a Reverse Proxy and SSL/TLS.
161180

162-
### 3.1. Creating a reverse proxy with [Nginx](https://www.nginx.com/)
181+
### 5.1. Creating a reverse proxy with [Nginx](https://www.nginx.com/)
163182

164183
A reverse proxy is basically an application that will handle every communication between the outside world and your internal applications. Nginx will receive external HTTP requests and redirect them to Meilisearch. When Meilisearch has done its amazing job, it will communicate its response to Nginx, which will then transfer the latter to the user who originally sent the request. This is a common way to isolate and protect any application by adding a robust, secure, and fast gate-keeper such as Nginx, one of the safest and most efficient tools available online, and of course, open-source!
165184

@@ -212,7 +231,7 @@ If you want to learn more about using Nginx as a Reverse Proxy, see [this dedica
212231

213232
The only remaining problem is that Meilisearch processes requests via HTTP without any additional security. The content that is being transmitted over HTTP could easily be read or modified by attackers, and someone could get full or partial access to your data. In order to prevent this to happen, it's important to use the HTTPS, which will enable you to use a SSL/TLS certificate, and securely transmit data.
214233

215-
### 3.2. Set up SSL/TLS for your Meilisearch
234+
### 5.2. Set up SSL/TLS for your Meilisearch
216235

217236
SSL will let the user or client establish an authenticated connection to Meilisearch. In this way, a user can verify server's identity before sending sensitive data or making any request to it. Then, data is sent in an encrypted way that only Meilisearch server will be able to decrypt, providing you a fast, reliable, and automatic layer of security.
218237

@@ -225,7 +244,7 @@ To illustrate this, if you had registered your domain name `example.com`, reques
225244

226245
Once your domain name has been set up, you are ready to configure SSL/TLS and use HTTPS. You have two different options to achieve this goal. The first one is using [Certbot](https://certbot.eff.org/), an amazing, free, and very easy to use tool. If you already have SSL certificates issued from a `Certificate Authority or CA` for your domain name, the second option covers the steps you need to follow. Then, you will be ready to use Meilisearch safely in production!
227246

228-
#### 3.2. Option A: Certbot
247+
#### 5.2.1. Option A: Certbot
229248

230249
Using certbot in your Linux server is very straightforward. This tool will generate a free SSL/TLS certificate for your domain name, and automatically handle its installation on your server. The certbot documentation contains detailed instructions for many operating systems and servers, but we will follow the instructions for [Certbot on Debian with Nginx](https://certbot.eff.org/instructions?ws=nginx&os=debianbuster).
231250

@@ -254,7 +273,7 @@ change by editing your web server's configuration.
254273
255274
We recommend that you choose option 2, to redirect HTTP to HTTPS and always use a secure connection. You should be able to request your domain name with SSL as in `https://example.com` or `https://example.com/indexes`.
256275
257-
#### 3.2. Option B: Custom SSL/TLS certificates
276+
#### 5.2.2. Option B: Custom SSL/TLS certificates
258277
259278
When a `Certificate Authority` issues a SSL certificate for you, you receive at least two files with encrypted keys:
260279

0 commit comments

Comments
 (0)