EverKB

Knowledge Base Ever

Namestite MongoDB4 na CentOS7

2019-11-15 11:30:33

Oznaka: CentOS, MongoDB, CentOS7, MongoDB4, Install MongoDB, Namestite MongoDB

Uredi datoteko /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

Namestite z YUM

yum -y install mongodb-enterprise

Ustvarite podatkovni imenik in imenik ter dajte dovoljenja imeniku

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

Nastavite škorenj in zaženite storitev

systemctl enable mongod
systemctl start mongod

Ustvari uporabnika

[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" ]
...   }

Omogoči pooblaščeno prijavo

MongoDB je privzeto dostopen samo v tem računalniku, dovoljeno prijavo pa lahko omogočite tako, da spremenite datoteko /etc/mongod.conf.

Spremenite bindIp na 0.0.0.0 in znova zaženite storitev, potem ko dodate dovoljeno konfiguracijo pod vrstico #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
Na tej točki lahko odjemalca uporabite za daljinsko povezavo. Konfiguracija odjemalca je naslednja:

IP: [MongoDB IP]
Vrata: 27017
Obrazec za avtorizacijo: admin
Uporabnik: admin
Geslo: admin

Preverite, ali je namestitev uspešna, preizkusite dodatke in izbrise v ukazni vrstici 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

Oznaka

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