[root@MYSQL01 ~]# mongo 172.16.59.21:27017
MongoDB shell version v5.0.5
connecting to: mongodb://172.16.59.21:27017/test?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("6297fc54-42a2-47b5-b26f-fae0ec85c21d") }
MongoDB server version: 5.0.5
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
---
The server generated these startup warnings when booting: 
        2022-01-18T18:03:35.688+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2022-01-18T18:03:35.688+08:00: You are running this process as the root user, which is not recommended
        2022-01-18T18:03:35.691+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2022-01-18T18:03:35.692+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
        2022-01-18T18:03:35.692+08:00: Soft rlimits for open file descriptors too low
        2022-01-18T18:03:35.692+08:00:         currentValue: 1024
        2022-01-18T18:03:35.692+08:00:         recommendedMinimum: 64000
---
---
        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()
---
> 

> use admin
switched to db admin
> cfg={ _id:"testrs", members:[ {_id:0,host:'172.16.59.21:27017',priority:2}, {_id:1,host:'172.16.59.22:27017',priority:1},   {_id:2,host:'172.16.59.23:27017',arbiterOnly:true}] };
{
        "_id" : "testrs",
        "members" : [
                {
                        "_id" : 0,
                        "host" : "172.16.59.21:27017",
                        "priority" : 2
                },
                {
                        "_id" : 1,
                        "host" : "172.16.59.22:27017",
                        "priority" : 1
                },
                {
                        "_id" : 2,
                        "host" : "172.16.59.23:27017",
                        "arbiterOnly" : true
                }
        ]
}
> rs.initiate(cfg) 
{ "ok" : 1 }
testrs:SECONDARY> 


mongo 172.16.59.21:27017
mongo 172.16.59.22:27017
mongo 172.16.59.23:27017


java 连接 https://mongodb.github.io/mongo-java-driver/3.4/driver/tutorials/connect-to-mongodb/



testrs:PRIMARY> use test
switched to db test
testrs:PRIMARY> show collections
testrs:PRIMARY> db.test.insert({"name":"knight"});
WriteResult({ "nInserted" : 1 })
testrs:PRIMARY> show collections
test
testrs:PRIMARY> db.test.find()
{ "_id" : ObjectId("61e7eff27a1df073165312d1"), "name" : "knight" }
testrs:PRIMARY> 
testrs:PRIMARY> 

posted on   heidsoft  阅读(86)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
历史上的今天:
2014-01-18 linux下TUN/TAP虚拟网卡的使用
2014-01-18 日志挖掘软件
2014-01-18 网络虚拟化技术 TUN/TAP MACVLAN MACVTAP
2014-01-18 下载youtube 视频工具
2014-01-18 OpenStack tokens id获取测试



点击右上角即可分享
微信分享提示