This article will guide you through setting up MongoDB as an external database server for Evoko Home.
Difficulty: Advanced.
Intended audience: Database administrators.
Tools/Prerequisites:
- Evoko Home v2.4 or above
- MongoDB v3.4 with server and client features installed. MongoDB v3.6-4.0 should also work but are not tested and should be considered unsupported.
- Windows Command Prompt
Time required: 20 minutes.
Note: In the examples below, replace less than/greater than characters as well as the text contained within them by the appropriate value. Example: <MONGODB_PORT> should be replaced by 27017 if you would like to use the default port.
Step 1: Create authentication files
In order to start MongoDb you have to create the mongo configuration file first. The configuration file is typically located in /etc/mongod.conf on Linux and C:\Program Files\MongoDB\Server\X.X\bin\mongod.cfg on Windows, where X.X is the MongoDB version.
Create the file if it does not exist, and add the following contents to the configuration file:
dbpath=<PATH_TO_MONGODB_DATA_FOLDER>
logpath=<PATH_TO_MONGODB_LOG_FOLDER>
port=<MONGODB_PORT>
slowms=500
replSet=rs0
smallfiles=true
Manually create the MongoDB data and log folders you specified in the configuration file.
Step 2: Configure MongoDB server
Open a new elevated Command Prompt window and enter:
<PATH_TO_MONGODB_FOLDER>/bin/mongod.exe --config "<PATH_TO_MONGODB_CONFIG>"
In the above command, replace the bracketed text with the appropriate values.
Then open another elevated Command Prompt window and enter the following (one command per line, press enter after each command):
<PATH_TO_MONGODB_FOLDER>/bin/mongo.exe <DATABASE_NAME> --eval "rs.initiate({ _id:'rs0', members: [{ '_id': 1, 'host': '127.0.0.1:<PORT>', 'priority': 1 }]})"
<PATH_TO_MONGODB_FOLDER>/bin/mongo.exe admin --eval "rs.slaveOk(); db.createUser({ user: 'oplogger', pwd: '<MONGODB_PASS>', roles: [{ role: 'read', db: 'local' }] })"
<PATH_TO_MONGODB_FOLDER>/bin/mongo.exe admin --eval "rs.slaveOk(); db.runCommand({ replSetResizeOplog: 1, size: 1000 })"
<PATH_TO_MONGODB_FOLDER>/bin/mongo.exe admin --eval "rs.slaveOk(); db.runCommand({ compact: 'oplog.rs', force: true })"
<PATH_TO_MONGODB_FOLDER>/bin/mongo.exe <DATABASE_NAME> --eval "rs.slaveOk(); db.createUser({ user: '<MONGODB_USER>', pwd: '<MONGODB_PASS>', roles: ['readWrite'] })"
<PATH_TO_MONGODB_FOLDER>/bin/mongo.exe admin --eval "db.shutdownServer({ force: true })"
Step 3: Modify the configuration file to require authentication
Prepend this line to the mongo configuration file and save:
auth=true
Step 4: Create and start the MongoDB service
Enter the following in an elevated command prompt window:
<PATH_TO_MONGODB_FOLDER>/bin/mongod.exe --config "<PATH_TO_MONGODB_CONFIG>" --install
net start MongoDb