EverKB

Knowledge Base Ever

CentOS7에 MongoDB4 설치

2019-11-15 11:30:33

라벨: CentOS, MongoDB, CentOS7, MongoDB4, Install MongoDB, MongoDB 설치

/etc/yum.repos.d/mongodb-enterprise.repo파일 편집

[mongodb-enterprise]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/4.0/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

YUM을 사용하여 설치

yum -y install mongodb-enterprise

데이터 디렉토리 및 로그 디렉토리를 작성하고 디렉토리에 권한을 부여하십시오.

mkdir -p /var/lib/mongo
mkdir -p /var/log/mongodb
chown -R mongod:mongod /var/lib/mongo
chown -R mongod:mongod /var/log/mongodb

부팅 설정 및 서비스 시작

systemctl enable mongod
systemctl start mongod

사용자 만들기

[root@carbon ~]# mongo
MongoDB shell version v4.0.11
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("bf1a80fb-6a70-4bdb-86c7-8b3587400f87") }
MongoDB server version: 4.0.11
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/

MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > db.createUser(
...   {
...     user: "admin",
...     pwd: "admin",
...     roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
...   }

인증 된 로그인 사용

기본적으로 MongoDB는이 머신에서만 액세스 할 수 있으며 /etc/mongod.conf파일을 수정하여 인증 된 로그인을 활성화 할 수 있습니다.

bindIp를 0.0.0.0으로 변경하고 #secruity줄 아래에 인증 된 구성을 추가 한 후 서비스를 다시 시작하십시오.
# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

#security:
security:
  authorization: enabled
systemctl restart mongod
이 시점에서 클라이언트를 사용하여 원격으로 연결할 수 있습니다. 클라이언트 구성은 다음과 같습니다.

IP : [MongoDB IP]
포트 : 27017
승인 양식 : admin
사용자 : admin
비밀번호 : admin

설치가 성공적인지 확인하고 mongo 명령 행에서 추가 및 삭제를 테스트하십시오.

[root@carbon ~]# mongo --port 27017 -u "admin" --authenticationDatabase "admin" -p
MongoDB shell version v4.0.11
Enter password: 
connecting to: mongodb://127.0.0.1:27017/?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("dfe7aba3-9c0c-45cb-bf7b-457453c218ce") }
MongoDB server version: 4.0.11
MongoDB Enterprise > db.foo.insert( { x: 1, y: 1 } )
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise > db.foo.find()
{ "_id" : ObjectId("5d45f6e21d57d1717b175746"), "x" : 1, "y" : 1 }
MongoDB Enterprise > db.foo.deleteOne({_id: ObjectId("5d45f6e21d57d1717b175746")})
{ "acknowledged" : true, "deletedCount" : 1 }
MongoDB Enterprise > db.foo.find()
MongoDB Enterprise > db.foo.drop()
true
MongoDB Enterprise > exit
bye

라벨

CentOS7 CentOS PHP Linux Python3 Python MySQL MariaDB YUM JavaScript CSS Redis MySQL8 caching_sha2_password HTML mysql_native_password PHP7 mssql-tools register_shutdown_function Symfony File Upload php-fpm sqlsrv Zend Framework ADDDATE DevExpress JetBrain network interface Shadowsocks-Libev unixODBC-devel height Port 80 string Aura error_get_last password policy requirements SOCKS Web Development data INDENTIFIED BY msodbcsql Redis5 SVN Fedora Media Writer SQLAlchemy absolute Deepin jemalloc mysqlclient Shadowsocks toggle convert FuelPHP margin PHPUnit Framework ss5.passwd at-symbol Error Control Operator password SOCKET vps daemon process IIS MongoDB4 sudoers center Fatal Errors Phalcon SQL Server 2017 WiFi .htaccess DATE_SUB set_error_handler TestCase Compiling PHP frequency conflict PHPUnit ss5.conf apr Elasticsearch7.3 particles.js Slim Vincent Garreau daemon HTTP MongoDB Sudo Failed to build these modules: _uuid pg_bha.conf SQL Server width DATE_ADD ip command MySQL-python scrollbar Tcp BBR Compiling Apache Frameworks libpython3.7m.so.1.0 PHPStorm ss5-3.8.9 Apache2.4 Elasticsearch NodeJs show VIM CURLOPT_POSTFIELDS Minimal ISO substr Bluetooth Failed to build these modules: _ctypes PECL SQL Date Funcitons Wi-Fi date sub INTERVAL root Tag Cloud CodeIgniter font-size Laravel ss5 apache httpd dual network interfaces node.js ShadowsocksR vertical-align CURLFille horiz-align mb_substr PyCharm SUBDATE BarManager exec PEAR SOCKS5 Proxy Server WebStorm date add IntelliJIDEA remi Tag Chrome find PHP5.5 src Apache du jQuery nginx Shadowsocks-Python V2Ray cURL hide MariaDB10.4 PostgreSQL sub folder availability eth0 pdo_sqlsrv SOCKS5 Web Server date Install MongoDB

최신 기사