High-level goals
Moving MySQL to remote
- Choose any relational database service to host the MySQL on a remote instance. The database services can be AWS RDS or Azure DB.
- Select a compatible version of MySQL for a remote instance. The remote instance should be of the same version as of local MySQL. You can check the local version using the command mysql --version (for eg: 5.7.22).
- Give the MySQL instance proper name, enter username (i.e master username) as admin and type a strong password for security reasons.
- Choose the MySQL instance properties, backup plan and optimization objectives. Normally, these objectives can not be achieved using local MySQL.
- After a MySQL instance is created, note down the hostname/end-point and credentials (i.e master username and its password). The hostname and credentials will be needed for either MySQL client or Open Edx instance to connect to the remote instance.
- Create a dump of the local MySQL which includes edxapp and edxapp_csmh databases. You can use mysql dump command (i.e mysqldump) and use relevant users for creating dump (i.e edxapp001 for edxapp and edxapp_cmsh001 for edxapp_csmh). It will prompt for a password, which is defined in my-password.yml file (i.e EDXAPP_MYSQL_PASSWORD and EDXAPP_MYSQL_CSMH_PASSWORD).The edxapp database is used for storing user related data for both LMS and Studio. While edxapp_csmh used to record for each attempt that learners make to answer problem types.
- Connect to the remote MySQL instance using mysql client to create edxapp and edxapp_csmh databases. Then restore each database with the dump created in step 6. For connecting to a remote MySQL instance, use the hostname and credentials created in step 5.
- Use the same hostname and credentials to point your Open Edx instance to your remote MySQL instance. For this, open lms.auth.json and cms.auth.json and replace the HOST, USER and PASSWORD values. For instance:
"DATABASES": {
"default": {
"ATOMIC_REQUESTS": true,
"CONN_MAX_AGE": 0,
"ENGINE": "django.db.backends.mysql",
"HOST": "demo-db.cdyyt8rxogtp.us-east-1.rds.amazonaws.com",
"NAME": "edxapp",
"OPTIONS": {},
"PASSWORD": "V2dqr6JBHkhbTs2V",
"PORT": "3306",
"USER": "admin"
},
"read_replica": {
"CONN_MAX_AGE": 0,
"ENGINE": "django.db.backends.mysql",
"HOST": "demo-db.cdyyt8rxogtp.us-east-1.rds.amazonaws.com",
"NAME": "edxapp",
"OPTIONS": {},
"PASSWORD": "V2dqr6JBHkhbTs2V",
"PORT": "3306",
"USER": "admin"
},
"student_module_history": {
"CONN_MAX_AGE": 0,
"ENGINE": "django.db.backends.mysql",
"HOST": "demo-db.cdyyt8rxogtp.us-east-1.rds.amazonaws.com",
"NAME": "edxapp_csmh",
"OPTIONS": {},
"PASSWORD": "V2dqr6JBHkhbTs2Vn",
"PORT": "3306",
"USER": "admin"
}
}
Moving MongoDB to remote
To move MongoDB to a remote instance, you will need a Linux machine preferably Ubuntu 16.04 LTS. The Linux machine can be taken from AWS EC2 or Azure VM.
Before installing MongoDB, open inbound port 27017 and whitelist the Open Edx instance IP on Linux machine Network Security Group. The MongoDB runs on 27017 port and this port should be left open, so that an Open Edx instance can communicate in a secure environment.
Once the Linux machine has been configured, you should have SSH access to the machine in the form of a .pem key along with the username. If you are not able to connect via SSH, then look for the inbound port and add 22 port in it. The SSH uses port 22 for secure communication and it should only be filled with the IP of the servers that you want to give access to MongoDB.
Now check the local MongoDB version using command mongo --version (for eg: 3.2.16) and connect the Linux machine to install the same version on it.
Once connected to the Linux machine, run the following commands to install MongoDB.
wget -qO - https://www.mongodb.org/static/pgp/server-3.2.asc | sudo apt-key add - echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list sudo apt-get update sudo apt-get install -y mongodb-org
This will take some time and after the process you can check your MongoDB status. It will show you status as active (running).
sudo service mongod status
After successful installation of MongoDB on a Linux machine, it needs to run publicly. For this, change the bindIp from 127.0.0.1 to 0.0.0.0 in the file /etc/mongod.conf. Otherwise, Open Edx would not be able to communicate to MongoDB.
Create a dump of the local MongoDB which includes edxapp, cs_comments_service, and admin databases. The edxapp and admin are conventional database for storing user related information. While cs_comments_service is responsible to store voting and nested comments. You can use mongo dump command (i.e mongodump) and use relevant users for creating a dump (i.e edxapp for edxapp, cs_comments_service for cs_comments_service and admin for admin). The password will be found in my-password.yml (i.e EDXAPP_MONGO_PASSWORD, FORUM_MONGO_PASSWORD and MONGO_ADMIN_PASSWORD)
Now, move the dump using scp to the Linux machine in which MongoDB is installed and restore the dump using mongorestore.
After that, the final step is to point the Open Edx instance to the MongoDb instance. For this you need to change the configuration of LMS, CMS and Forum.
For LMS and CMS, open lms.auth.json and cms.auth.json and search for 27017 and replace all the occurences for "host": "localhost" to "host": "Your-Mongo-Server-IP". For instance:
"DOC_STORE_CONFIG": { "collection": "modulestore", "connectTimeoutMS": 2000, "db": "edxapp", "host": "{{Your-Mongo-Server-IP}}", "password": "gRhR9psJvrQInTsFPxKvOFYWBS8CwOk7wTj", "port": 27017, "read_preference": "SECONDARY_PREFERRED", "replicaSet": "", "socketTimeoutMS": 3000, "ssl": false, "user": "edxapp" }
For forum, activate forum user and virtual environment. Now, open cs_comments_service/config/mongoid.yml.
Replace this:
development: clients: default: <<: *default_uri <<: *default_client
With:
development: clients: default: <<: *default_client database: cs_comments_service hosts: - 172.31.45.195:27017