安裝
新增repo檔案並加入
# vim /etc/yum.repos.d/mongodb.repo
[MongoDB]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
安裝
# yum install mongodb-org
啟動 - For CentOS 8/7
# systemctl start mongod.service
開機自動啟動 - For CentOS 8/7
# systemctl enable mongod.service
查版本
# mongod --version
db version v4.2.5
git version: 2261279b51ea13df08ae708ff278f0679c59dc32
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
使用
# mongo
MongoDB shell version v4.2.5
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("317a2efd-8d1e-4781-abcf-38d8a0907eb4") }
MongoDB server version: 4.2.5
Welcome to the MongoDB shell.
...
> use mydb;
switched to db mydb
> db.test.save( { a: 1 } )
WriteResult({ "nInserted" : 1 })
> db.test.find()
{ "_id" : ObjectId("5e84098b7cf1f4aa0558d5e6"), "a" : 1 }
使用
客戶端使用PHPStorm的Plugins: Mongo Plugin
配置連線
因為 IP+端口不通,可使用SSH通道,URL: IP(不需指定port)
參考資料
https://tecadmin.net/install-mongodb-on-centos/ How to Install MongoDB 4.2 on CentOS/RHEL 8/7/6
沒有留言:
張貼留言