# Red Hat/Cent OS

## MongoDB

Petio supports two ways of connecting to a Mongo Database instance, locally or remote. We recommend the locally hosted MongoDB option.

### **MongoDB Locally**

* Configure the package management system (yum)
* Create a /etc/yum.repos.d/mongodb-org-4.4.repo file so that you can install MongoDB directly using yum:

```bash
sudo nano /etc/yum.repos.d/mongodb-org-4.4.repo
```

* Paste in the nano / terminal window:

```bash
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
```

* Press: "CTRL + O" to save and "CTRL+X" to exit.
* To install the latest stable version of MongoDB, issue the following command:

```bash
sudo yum install -y mongodb-org
```

* Start MongoDB:

```bash
sudo systemctl start mongod
```

* Verify that MongoDB has started successfully:

```bash
sudo systemctl status mongod
```

* To make sure MongoDB starts after restart use:

```bash
sudo systemctl enable mongod
```

### MongoDB Locally - On A Different Host

By default, MongoDB doesn’t allow remote connections.

* Locate your `mongod.conf` and edit it with your favorite editor. Include any local IP addresses you want to allow to connect to your MongoDB instance.

```bash
vim /etc/mongod.conf
# /etc/mongod.conf
# Listen to local and LAN interfaces.
bind_ip = 127.0.0.1,192.168.161.100
```

* Restart the `mongod` service after making these changes

```bash
sudo systemctl restart mongod
```

If there is a firewall, you might need to use `iptables` to allow access to MongoDB. Example below:

* Any connections can connect to MongoDB on port 27017

```bash
iptables -A INPUT -p tcp --dport 27017 -j ACCEPT
```

* Only certain IPs can connect to MongoDB on port 27017

```bash
iptables -A INPUT -s <ip-address> -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d <ip-address> -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
```

### MongoDB Remotely

* Register for Atlas [here](https://www.mongodb.com/cloud/atlas/register).
* Create a free cluster.

![](https://1035527593-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWo9pUWfgX7wVD6UyHV%2F-MWpvMDmc1hQrVGSebHt%2F-MWpwKzvMm2w27RFKx9r%2Fremote_mongodb_cluster.jpg?alt=media\&token=5590fd95-9797-40b0-9d00-04e4ff1bc179)

* Change the provider or region if you need to. It may take some time to create the cluster.

![](https://1035527593-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWo9pUWfgX7wVD6UyHV%2F-MWpvMDmc1hQrVGSebHt%2F-MWpwKzuKe3yy1gb7f_A%2Fremote_mongodb_server_region.jpg?alt=media\&token=1596e211-c05e-448e-a291-071c07f203e4)

* After the cluster is made, click on connect and select MongoDB Compass and follow the instructions on screen.

![](https://1035527593-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWo9pUWfgX7wVD6UyHV%2F-MWpvMDmc1hQrVGSebHt%2F-MWpwKztq-smEhPkWGz9%2Fremote_mongodb_compass.jpg?alt=media\&token=91743398-7580-4d94-91b7-6c093ec07ad4)

* Move on to the next section to start [installing Petio](#installing-petio).

## Installing Petio

* Create a user for Petio:

```bash
sudo useradd -M --shell=/bin/false petio
```

* Make a directory for Petio:

```bash
sudo mkdir /opt/Petio
```

* Download the latest version of Petio:

```bash
sudo wget https://petio.tv/releases/latest -O petio-latest.zip
```

* Extract Petio to the directory we just made:

```bash
sudo unzip petio-latest.zip -d /opt/Petio
```

* Change ownership of the directory for Petio:

```bash
sudo chown -R petio:petio /opt/Petio
```

* Create the petio service with systemd:

```bash
sudo vi /etc/systemd/system/petio.service

[Unit]
Description=Petio a content request system
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=on-failure
RestartSec=1
ExecStart=/opt/Petio/bin/petio-linux
User=petio

[Install]
WantedBy=multi-user.target
```

* Reload systemd:

```bash
sudo systemctl daemon-reload
```

* Start Petio:

```bash
sudo systemctl start petio
```

Once you've completed theses steps, you can navigate to `http://<hostname>:7777` to start [configuring Petio](https://docs.petio.tv/configuration/first-time-setup).
