ETC
MongoDB 간단 설치
후니옹
2024. 5. 6. 02:13
- MongoDB 테스트 목적으로 간단하게 설치
- MongoDB를 Grafana로 모니터링 하고 싶어서 직접 MongoDB 구성함
## Mongo Repo 추가##
$ vi /etc/yum.repos.d/mongodb-org.repo
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
$ yum repolist (올바른지 확인)
$ yum install mongodb-org
$ systemctl start mongod (시작)
$ systemctl stop mongod (중지)
$ systemctl reload mongod (설정파일 다시 읽기 및 반영)
$ tail /var/log/mongodb/mongod.log (로그)
## 접속 ##
# mongo localhost:27017
MongoDB shell version v3.4.24
connecting to: mongodb://localhost:27017/test
MongoDB server version: 3.4.24
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
Server has startup warnings:
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten]
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten]
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten]
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten]
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2020-02-18T00:34:40.300+0000 I CONTROL [initandlisten]
> db
test
> show dbs
admin 0.000GB
local 0.000GB
>
## 계정만들기(admin) ##
> use admin
switched to db admin
> db.createUser(
... {
... user: "testadmin",
... pwd: "abc123",
... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
... }
... )
Successfully added user: {
"user" : "testadmin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
## 새로만든계정으로 접속 ##
mongo --port 27017 -u "testadmin" -p "abc123" --authenticationDatabase "admin"
## 모니터링 용 계정 생성 ##
use admin
db.createUser(
{
user: "monitoruser",
pwd: "monitoruser",
roles: [ { role: "clusterMonitor", db: "admin" } ]
}
)