end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

install mongodb ver.4.2.0 from src

gcc ver.8.3.0の準備もできたので、 mongodb に付属の docs/building.md と https://shoken.hatenablog.com/entry/2015/07/13/162548 を参考に実施。

download & build & install

https://www.mongodb.com/download-center/community

$ wget https://fastdl.mongodb.org/src/mongodb-src-r4.2.0.tar.gz
$ tar -xvf mongodb-src-r4.2.0.tar.gz
$ cd mongodb-src-r4.2.0
$ less docs/building.md

$ sudo /usr/local/python3/bin/pip3 install -r etc/pip/compile-requirements.txt

# ↓私の環境では3時間程、かかりました
$ /usr/local/python3/bin/python3 buildscripts/scons.py core

$ sudo /usr/local/python3/bin/python3 buildscripts/scons.py \
  --prefix=/usr/local/mongodb install

設定

$ wget https://raw.githubusercontent.com/mongodb/mongo/master/rpm/mongod.conf
$ vi mongod.conf
  old)  dbPath: /var/lib/mongo
  new)  dbPath: /home/mongod/data

$ sudo mv mongod.conf /etc/mongod.conf

$ sudo mkdir /var/log/mongodb
$ sudo mkdir /var/run/mongodb
$ sudo mkdir /home/mongo/data

で、試しに rootで起動 & 接続.

(色々とwarningが表示されますが、最後に「>」が表示され起動されたことが確認できます)

(この起動により root権限で /home/mongod/data 以下に様々なfileが作成されますので mongod 停止後、sudo rm -rf /home/mongod/data/* します)

起動
$ sudo /usr/local/mongodb/bin/mongod -f /etc/mongod.conf

接続確認
$ /usr/local/mongodb/bin/mongo
MongoDB shell version v4.2.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("3a4e52bf-3401-4324-be73-22efc394d473") }
MongoDB server version: 4.2.0
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
  :
2019-08-14T03:12:55.595+0900 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-08-14T03:12:55.595+0900 I  CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

> 

停止
$ sudo kill `cat /var/run/mongodb/mongod.pid`
$ sudo rm /var/lib/mongo/mongod.lock

掃除
$ sudo rm -rf /home/mongod/data/*

自動起動設定

$ sudo /usr/sbin/groupadd -r mongod
$ sudo /usr/sbin/useradd -r -g mongod mongod

$ sudo chown -R mongod:mongod /usr/local/mongodb
$ sudo chown -R mongod:mongod /var/log/mongodb
$ sudo chown -R mongod:mongod /var/run/mongodb

$ wget https://raw.githubusercontent.com/mongodb/mongo/master/rpm/mongod.service
$ vi mongod.service
 old) ExecStart=/usr/bin/mongod $OPTIONS
 new) ExecStart=/usr/local/mongodb/bin/mongod $OPTIONS

$ sudo mv mongod.service /usr/lib/systemd/system/
$ cd /usr/lib/systemd/system/
$ sudo systemctl enable mongod
$ sudo systemctl start mongod.service
$ sudo systemctl status mongod.service