MongoDB is a database which stores data without the need for a pre-established model ("strict description") of this data. In practice: I can save something into MongoDB without spending time creating tables and stuff. Just save a JSON doc, that’s it. Show
MongoDB alone is great, but I will store gigabytes of data, with several text fields and some simple graph logic as well. Elasticsearch is known for managing well the indexes and queries related to these data types.
3. Installing MongoDBsource: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list sudo apt-get update sudo apt-get install -y mongodb-org disable Transparent Huge Pages as per https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/ create a new file: sudo vi /etc/init.d/disable-transparent-hugepages paste this in the text editor:
Make the file executable: sudo chmod 755 /etc/init.d/disable-transparent-hugepages Make the file to be ran on reboot: sudo update-rc.d disable-transparent-hugepages defaults Start Mongo: sudo service mongod start Check that it runs fine: sudo cat /var/log/mongodb/mongod.log → There should be a line "[initandlisten] waiting for connections on port <port>" And now stop it, as we will need to run it differently for elasticsearch: sudo service mongod stop 3. Install Elasticsearchsource: https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html Download the public signing key: wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - Then: sudo apt-get update0 sudo apt-get update1 sudo apt-get update sudo apt-get update3 sudo apt-get update4 sudo apt-get update5 4. Config Elasticsearchsudo apt-get update6 → switch this param to true: bootstrap.memory_lock: true You then need to make sure the JVM Heap size is no more than half the RAM. First fix a memory param: sudo apt-get update7 Add these lines: LimitMEMLOCK=infinity Adjust resource limits: sudo apt-get update8 Add line: elasticsearch - nofile 65536 Add a jvm parameter: sudo vi /etc/elasticsearch/jvm.options Add this line: -Djava.io.tmpdir=/var/tmp 5. Install the mongo to elasticsearch connectiona. elastic2-doc-managerThis is a doc manager by mongodb labs. Source: https://github.com/mongodb-labs/elastic2-doc-manager sudo apt-get update9 b. run Mongo as a replicasetsudo service mongod stop Create the path for your db (if needed) sudo mkdir -p /data/db sudo vi /etc/init.d/disable-transparent-hugepages1 sudo vi /etc/init.d/disable-transparent-hugepages2 Then: sudo vi /etc/init.d/disable-transparent-hugepages3 sudo vi /etc/init.d/disable-transparent-hugepages4 sudo vi /etc/init.d/disable-transparent-hugepages5 6. Install kibanaKibana is the visualization engine for elastic. sudo vi /etc/init.d/disable-transparent-hugepages6 Configure Kibana to start automatically at boot: sudo vi /etc/init.d/disable-transparent-hugepages7 7. Install X-packsudo vi /etc/init.d/disable-transparent-hugepages8
cd /usr/share/elasticsearch sudo bin/elasticsearch-plugin install x-pack cd /usr/share/kibana sudo bin/kibana-plugin install x-pack 8. Disable the security component of X-PackThis security component is hard to configure, and we don’t need it if we run elasticsearch behind a web server and a reverse proxy, on a single machine. Add xpack.security.enabled: false to /etc/elasticsearch/elasticsearch.yml and to /etc/kibana/kibana.yml Also in the same kibana.conf file, change the default username and passwd to "elastic" and "changeme" and leave the quotes
9. Install the Mongo-connector for ElasticSearchSource: https://blog.jixee.me/how-to-use-mongo-connector-with-elasticsearch/ sudo vi /etc/init.d/disable-transparent-hugepages9 Edit the conf of Mongo to turn on replicasets: 0Uncomment "replication", add two lines: 1 210. Start elasticsearch and Kibana 3You can check that the connection is made here, your Mongo collections should be listed on this page: |