Liunx搭建Mongodb开发环境

1.Liunx搭建Mongodb开发环境
【1】官网下载Mongodb安装包:mongodb-linux-x86_64-rhel70-3.6.4.tgz并上传到服务目录: /usr/local/mongodb
【2】进入到服务器: cd /usr/local/mongodb,并入输入tar -xvf 命令解压安装包: tar -xvf mongodb-linux-x86_64-rhel70-3.6.4.tgz
 
[root@bella-master ~]# cd /usr/local/mongodb
[root@bella-master mongodb]# tar -xvf mongodb-linux-x86_64-rhel70-3.6.4.tgz
mongodb-linux-x86_64-rhel70-3.6.4/README
mongodb-linux-x86_64-rhel70-3.6.4/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-rhel70-3.6.4/MPL-2
mongodb-linux-x86_64-rhel70-3.6.4/GNU-AGPL-3.0
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongodump
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongorestore
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongoexport
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongoimport
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongostat
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongotop
mongodb-linux-x86_64-rhel70-3.6.4/bin/bsondump
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongofiles
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongoreplay
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongoperf
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongod
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongos
mongodb-linux-x86_64-rhel70-3.6.4/bin/mongo
mongodb-linux-x86_64-rhel70-3.6.4/bin/install_compass
[root@bella-master mongodb]#
【3】解压之后对解压文件夹进行重命名: mv mongodb-linux-x86_64-rhel70-3.6.4 mongodb-3.6.4
[root@bella-master mongodb]# ll
total 97084
drwxr-xr-x 3 root root     4096 May 10 02:56 mongodb-linux-x86_64-rhel70-3.6.4
-rw-r--r-- 1 root root 99406523 May 10 02:51 mongodb-linux-x86_64-rhel70-3.6.4.tgz
[root@bella-master mongodb]# mv mongodb-linux-x86_64-rhel70-3.6.4 mongodb-3.6.4
[root@bella-master mongodb]# ll
total 97084
drwxr-xr-x 3 root root     4096 May 10 02:56 mongodb-3.6.4
-rw-r--r-- 1 root root 99406523 May 10 02:51 mongodb-linux-x86_64-rhel70-3.6.4.tgz
[root@bella-master mongodb]#
【4】在Mongodb安装目录创建repository文件夹,并且在其文件夹下创建conf,data,logs文件夹:
[root@bella-master mongodb]# mkdir repository
[root@bella-master mongodb]# ll
total 97088
drwxr-xr-x 3 root root     4096 May 10 02:56 mongodb-3.6.4
-rw-r--r-- 1 root root 99406523 May 10 02:51 mongodb-linux-x86_64-rhel70-3.6.4.tgz
drwxr-xr-x 2 root root     4096 May 10 03:03 repository
[root@bella-master mongodb]# cd repository/
[root@bella-master repository]# mkdir data
[root@bella-master repository]# mkdir logs
[root@bella-master repository]# cd data/
[root@bella-master data]# mkdir db
[root@bella-master data]#
【5】配置环境变量: vim /etc/profile
#Seetting MONGODB_HOME
export MONGODB_HOME=/usr/local/mongodb/mongodb-3.6.4
export PATH=${PATH}:${MONGODB_HOME}/bin
【6】在conf目录配置Mongodb环境: vim mongodb.conf
systemLog:
    verbosity: 0  
    quiet: false  
    path: /usr/local/mongodb/repository/logs/mongodb.log
    logAppend: false  
    destination: file  
processManagement:  
    fork: true  
    pidFilePath: /usr/local/mongodb/repository/pid/mongodb.pid
net:  
    bindIp: 127.0.0.1  
    port: 27017  
    maxIncomingConnections: 65536  
    wireObjectCheck: true  
    ipv6: false   
storage:  
    dbPath: /usr/local/mongodb/repository/data/db  
    indexBuildRetry: true  
    journal:  
        enabled: true  
    directoryPerDB: false  
    engine: mmapv1  
    syncPeriodSecs: 60   
    mmapv1:  
        quota:  
            enforced: false  
            maxFilesPerDB: 8  
        smallFiles: true      
        journal:  
            commitIntervalMs: 100  
    wiredTiger:  
        engineConfig:  
            cacheSizeGB: 8  
            journalCompressor: snappy  
            directoryForIndexes: false    
        collectionConfig:  
            blockCompressor: snappy  
        indexConfig:  
            prefixCompression: true  
operationProfiling:  
    slowOpThresholdMs: 100  
    mode: off
【7】输入:mongod -f mongodb.conf
[root@bella-master conf]# mongod -f mongodb.conf
2018-05-10T03:53:44.561+0800 W CONTROL  [main] Option: storage.mmapv1.journal.commitIntervalMs is deprecated. Please use storage.journal.commitIntervalMs instead.
about to fork child process, waiting until server is ready for connections.
forked process: 25472
child process started successfully, parent exiting
【8】输入:mongo
[root@bella-master conf]# mongo
MongoDB shell version v3.6.4
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.4
Server has startup warnings:
2018-05-10T03:53:44.610+0800 I STORAGE  [initandlisten]
2018-05-10T03:53:44.610+0800 I STORAGE  [initandlisten] ** WARNING: Readahead for /usr/local/mongodb/repository/data/db is set to 4096KB
2018-05-10T03:53:44.610+0800 I STORAGE  [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less
2018-05-10T03:53:44.610+0800 I STORAGE  [initandlisten] **           http://dochub.mongodb.org/core/readahead
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten]
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten]
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten]
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten]
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten]
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 3895 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
2018-05-10T03:53:44.852+0800 I CONTROL  [initandlisten]
>
【9】开放端口: 27017
[root@bella-master conf]# systemctl start firewalld.service
[root@bella-master conf]# firewall-cmd --list-ports
3306/tcp 6379/tcp 8080/tcp 8081/tcp 15672/tcp 8161/tcp 61616/tcp
[root@bella-master conf]# firewall-cmd --zone=public --add-port=27017/tcp --permanent
success
[root@bella-master conf]# firewall-cmd --reload
success
【10】阿里云新建安全组:27017/27017
【11】数据库授权配置:
【1】创建数据库登录用户名和密码:
    db.createUser({user:"root",pwd:"Bella20180420",roles:[{role:"userAdminAnyDatabase",db:"admin"}]});
2】数据角色:
   具体角色: 
Read :允许用户读取指定数据库
readWrite :允许用户读写指定数据库
dbAdmin :允许用户在指定数据库中执行管理函数,如索引创建、删除,查看统计或访问system.profile
userAdmin :允许用户向system.users集合写入,可以找指定数据库里创建、删除和管理用户
clusterAdmin :只在admin数据库中可用,赋予用户所有分片和复制集相关函数的管理权限。
readAnyDatabase :只在admin数据库中可用,赋予用户所有数据库的读权限
readWriteAnyDatabase :只在admin数据库中可用,赋予用户所有数据库的读写权限
userAdminAnyDatabase :只在admin数据库中可用,赋予用户所有数据库的userAdmin权限
dbAdminAnyDatabase :只在admin数据库中可用,赋予用户所有数据库的dbAdmin权限。
root :只在admin数据库中可用。超级账号,超级权限
【3】授权用户和密码: db.auth('root','Bella20180420');
【4】授权命令:
db.createUser({user:"root",pwd:"Bella20180420", roles:[{role:"readWrite", db:"admin"}]});
db.grantRolesToUser("root", [{role:"readWrite", db:"admin"}]);
db.grantRolesToUser("root", [{role:"dbAdminAnyDatabase", db:"admin"}]);
db.grantRolesToUser("root", [{role:"dbAdminAnyDatabase", db:"admin"}]);
db.grantRolesToUser("root", [{role:"readAnyDatabase", db:"admin"}]);
db.grantRolesToUser("root", [{role:"userAdmin", db:"admin"}]);
db.grantRolesToUser("root", [{role:"dbAdmin", db:"admin"}]);
db.grantRolesToUser("root", [{role:"dbAdmin", db:"admin"}]);
 
db.createUser({user:"root",pwd:"Bella20180420", roles:[{role:"readWrite", db:"config"}]});
db.grantRolesToUser("root", [{role:"readWrite", db:"config"}]);
db.grantRolesToUser("root", [{role:"dbAdminAnyDatabase", db:"config"}]);
db.grantRolesToUser("root", [{role:"dbAdminAnyDatabase", db:"config"}]);
db.grantRolesToUser("root", [{role:"readAnyDatabase", db:"config"}]);
db.grantRolesToUser("root", [{role:"userAdmin", db:"config"}]);
db.grantRolesToUser("root", [{role:"dbAdmin", db:"config"}]);
db.grantRolesToUser("root", [{role:"dbAdmin", db:"config"}]);
 
db.createUser({user:"root",pwd:"Bella20180420", roles:[{role:"readWrite", db:"local"}]});
db.grantRolesToUser("root", [{role:"readWrite", db:"local"}]);
db.grantRolesToUser("root", [{role:"dbAdminAnyDatabase", db:"local"}]);
db.grantRolesToUser("root", [{role:"dbAdminAnyDatabase", db:"local"}]);
db.grantRolesToUser("root", [{role:"readAnyDatabase", db:"local"}]);
db.grantRolesToUser("root", [{role:"userAdmin", db:"local"}]);
db.grantRolesToUser("root", [{role:"dbAdmin", db:"local"}]);
db.grantRolesToUser("root", [{role:"dbAdmin", db:"local"}]);

猜你喜欢

转载自mazhilin.iteye.com/blog/2422588
今日推荐