💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
一、在centos7上操作 https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.6/x86_64/RPMS/ 1、创建yum仓库 ~~~ [root@node1 yum.repos.d]# vim mongodb-org-3.6.repo [mongodb-org-3.6] name = MongoDB Repository baseurl = https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.6/x86_64/ gpgcheck = 0 enabled = 1 ~~~ 或者 ~~~ [mongodb-org-3.4] name = MongoDB 3.4 baseurl = https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.4/x86_64/ gpgcheck = 0 enabled = 1 ~~~ 2、安装特定版本的MongoDB 官网下载地址:https://www.mongodb.com/download-center?jmp=homepage#community [root@node1 ~]# yum install -y mongodb-org-3.6.3 mongodb-org-server-3.6.3 mongodb-org-shell-3.6.3 mongodb-org-mongos-3.6.3 mongodb-org-tools-3.6.3 ![](https://box.kancloud.cn/799d389fedd96dbdfb2c04a4b5498a9e_796x506.png) 查看 ~~~ [root@node1 ~]# rpm -ql mongodb-org-server /etc/mongod.conf /lib/systemd/system/mongod.service /usr/bin/mongod /usr/share/doc/mongodb-org-server-3.6.3 /usr/share/doc/mongodb-org-server-3.6.3/GNU-AGPL-3.0 /usr/share/doc/mongodb-org-server-3.6.3/MPL-2 /usr/share/doc/mongodb-org-server-3.6.3/README /usr/share/doc/mongodb-org-server-3.6.3/THIRD-PARTY-NOTICES /usr/share/man/man1/mongod.1 /var/lib/mongo /var/log/mongodb /var/log/mongodb/mongod.log /var/run/mongodb ~~~ 修改配置文件/etc/mongod.conf ~~~ [root@node1 ~]# cat /etc/mongod.conf # mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # Where and how to store data. storage: dbPath: /var/lib/mongo (数据存放位置) journal: enabled: true # engine: # mmapv1: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces (监听地址和端口) net: port: 27017 bindIp: 10.2.13.187 # Listen to local interface only, comment to listen on all interfaces. #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options #auditLog: #snmp: ~~~ centos7上mongodb启动脚本(通过yum安装的) ~~~ [root@node1 system]# cat mongod.service [Unit] Description=High-performance, schema-free document-oriented database After=network.target Documentation=https://docs.mongodb.org/manual [Service] User=mongod Group=mongod Environment="OPTIONS=-f /etc/mongod.conf" ExecStart=/usr/bin/mongod $OPTIONS ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb PermissionsStartOnly=true PIDFile=/var/run/mongodb/mongod.pid Type=forking # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # locked memory LimitMEMLOCK=infinity # total threads (user+kernel) TasksMax=infinity TasksAccounting=false # Recommended limits for for mongod as specified in # http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings [Install] WantedBy=multi-user.target ~~~ 启动monogdb服务 [root@node1 system]# systemctl start mongod [root@node1 system]# ss -tunlp|grep 27017 tcp LISTEN 0 128 10.2.13.187:27017 *:* users:(("mongod",pid=16581,fd=11)) 启动日志: ~~~ [root@node1 ~]# systemctl start mongod [root@node1 ~]# tail -f /var/log/mongodb/mongod.log 2018-03-12T13:36:41.999+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-03-12T13:36:41.999+0800 I CONTROL [initandlisten] 2018-03-12T13:36:41.999+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2018-03-12T13:36:41.999+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-03-12T13:36:41.999+0800 I CONTROL [initandlisten] 2018-03-12T13:36:42.000+0800 I STORAGE [initandlisten] createCollection: admin.system.version with provided UUID: d3a9abae-e3e5-44a4-befa-a39c034af38c 2018-03-12T13:36:42.057+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.6 2018-03-12T13:36:42.062+0800 I STORAGE [initandlisten] createCollection: local.startup_log with generated UUID: efbf7369-9cfc-4278-96d0-705831cdc54f 2018-03-12T13:36:42.108+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongo/diagnostic.data' 2018-03-12T13:36:42.109+0800 I NETWORK [initandlisten] waiting for connections on port 27017 ~~~ 然后查看/var/lib/mongo ~~~ [root@node1 system]# cd /var/lib/mongo/ [root@node1 mongo]# ll total 60 -rw-------. 1 mongod mongod 4096 Feb 28 11:58 collection-0-5947962256860600967.wt -rw-------. 1 mongod mongod 4096 Feb 28 11:58 collection-2-5947962256860600967.wt drwx------. 2 mongod mongod 4096 Feb 28 11:58 diagnostic.data -rw-------. 1 mongod mongod 4096 Feb 28 11:58 index-1-5947962256860600967.wt -rw-------. 1 mongod mongod 4096 Feb 28 11:58 index-3-5947962256860600967.wt drwx------. 2 mongod mongod 4096 Feb 28 11:58 journal -rw-------. 1 mongod mongod 4096 Feb 28 11:58 _mdb_catalog.wt -rw-------. 1 mongod mongod 6 Feb 28 11:58 mongod.lock -rw-------. 1 mongod mongod 4096 Feb 28 11:58 sizeStorer.wt -rw-------. 1 mongod mongod 114 Feb 28 11:58 storage.bson -rw-------. 1 mongod mongod 48 Feb 28 11:58 WiredTiger -rw-------. 1 mongod mongod 4096 Feb 28 11:58 WiredTigerLAS.wt -rw-------. 1 mongod mongod 21 Feb 28 11:58 WiredTiger.lock -rw-------. 1 mongod mongod 892 Feb 28 11:58 WiredTiger.turtle -rw-------. 1 mongod mongod 4096 Feb 28 11:58 WiredTiger.wt ~~~ 防火墙配置 * selinux方面 semanage port -a -t mongod_port_t -p tcp 27017 * firewalld firewall -cmd --permanent --add-port=27017/tcp firewall-cmd reload 3、在windows上下载客户端mongoUVE工具 * http://download.informer.com/win-1192698656-b4a1ffcf-5508f5ea/installer-1.6.9.zip * https://www.mongodbmanager.com/files/mongodbmanagerpro_inst.exe 4、下载mongodb(php、python连接mongodb的驱动等) https://github.com/mongodb 客户端连接 [root@node1 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled [root@node1 ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag ~~~ [root@node1 ~]# mongo 10.2.13.187:27017 MongoDB shell version v3.6.3 connecting to: mongodb://10.2.13.187:27017/test MongoDB server version: 3.6.3 Server has startup warnings: 2018-03-12T13:49:13.347+0800 I STORAGE [initandlisten] 2018-03-12T13:49:13.347+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2018-03-12T13:49:13.347+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem 2018-03-12T13:49:16.074+0800 I CONTROL [initandlisten] 2018-03-12T13:49:16.074+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2018-03-12T13:49:16.074+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2018-03-12T13:49:16.074+0800 I CONTROL [initandlisten] > show dbs ------查看当前mongodb中有多少个数据库 admin 0.000GB config 0.000GB local 0.000GB > use admin ----切换到使用某个数据库 switched to db admin > show collections-----------显示当前数据库中有多少个集合 system.version ~~~ 第二部分:在ubuntu16.04系统上安装mongodb3.6.3 ~~~ 1、导入包管理系统使用的公钥 www@u-node1:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 [sudo] password for www: Executing: /tmp/tmp.rCF6o7ZOCv/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 gpg: requesting key 91FA4AD5 from hkp server keyserver.ubuntu.com gpg: key 91FA4AD5: public key "MongoDB 3.6 Release Signing Key <packaging@mongodb.com>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) www@u-node1:~$ 2、为MongoDB创建一个列表文件 www@u-node1:~$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse 3、更新 www@u-node1:~$ sudo apt-get update 4、安装mongodb3.6.3 www@u-node1:~$ sudo apt-get install -y mongodb-org=3.6.3 mongodb-org-server=3.6.3 mongodb-org-shell=3.6.3 mongodb-org-mongos=3.6.3 mongodb-org-tools=3.6.3 5、启动mongodb www@u-node1:~$ sudo service mongod start www@u-node1:~$ ss -tunlp|grep 27017 tcp LISTEN 0 128 10.2.13.178:27017 *:* www@u-node1:~$ tail -f /var/log/mongodb/mongod.log 2018-03-12T14:05:19.264+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=256M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress), 2018-03-12T14:05:20.330+0800 I CONTROL [initandlisten] 2018-03-12T14:05:20.330+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2018-03-12T14:05:20.330+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2018-03-12T14:05:20.330+0800 I CONTROL [initandlisten] 2018-03-12T14:05:20.417+0800 I STORAGE [initandlisten] createCollection: admin.system.version with provided UUID: 08ba056b-ddb0-495b-bb99-c4a2f27c54d6 2018-03-12T14:05:20.493+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.6 2018-03-12T14:05:20.499+0800 I STORAGE [initandlisten] createCollection: local.startup_log with generated UUID: 334ff311-7c66-4529-9266-6f31f02226b0 2018-03-12T14:05:20.533+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data' 2018-03-12T14:05:20.534+0800 I NETWORK [initandlisten] waiting for connections on port 27017 客户端连接 www@u-node1:~$ mongo 10.2.13.178:27017 MongoDB shell version v3.6.3 connecting to: mongodb://10.2.13.178:27017/test MongoDB server version: 3.6.3 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: 2018-03-12T14:05:19.263+0800 I STORAGE [initandlisten] 2018-03-12T14:05:19.263+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2018-03-12T14:05:19.263+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem 2018-03-12T14:05:20.330+0800 I CONTROL [initandlisten] 2018-03-12T14:05:20.330+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2018-03-12T14:05:20.330+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2018-03-12T14:05:20.330+0800 I CONTROL [initandlisten] > show dbs admin 0.000GB local 0.000GB > use admin switched to db admin > use test switched to db test > show collections ~~~