摘要:默認(rèn)關(guān)閉服務(wù)刪除用戶刪除用戶需要權(quán)限,會(huì)將所有數(shù)據(jù)庫中的用戶刪除刪除用戶權(quán)限要求沒有那么高,只刪除本數(shù)據(jù)中的用戶查詢所有用戶啟動(dòng)報(bào)錯(cuò)解決在系統(tǒng)上安裝之后報(bào)錯(cuò)。另外,用戶信息保存在中。比如數(shù)據(jù)庫和都有用戶,以登錄后不能夠登錄到進(jìn)行數(shù)據(jù)庫操作
Centos 7 [mongodb-org] name=MongoDB Repository baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/3.4/x86_64/ gpgcheck=0 enabled=1 Centos 6 [mongodb-org] name=MongoDB Repository baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/6Server/mongodb-org/3.4/ gpgcheck=0 enabled=1
yum install mongodb-org -y chkconfig mongod on service mongodb restart 修改監(jiān)聽地址 bindIp: 0.0.0.0 開啟認(rèn)證 修改配置文件/etc/mongodb.conf security: authorization: enabled 重啟mongodb sudo service mongodb restartMongoDB用戶角色配置
基本知識介紹 MongoDB基本的角色: 1.數(shù)據(jù)庫用戶角色:read、readWrite; 2.數(shù)據(jù)庫管理角色:dbAdmin、dbOwner、userAdmin; 3.集群管理角色:clusterAdmin、clusterManager、clusterMonitor、hostManager; 4.備份恢復(fù)角色:backup、restore; 5.所有數(shù)據(jù)庫角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase 6.超級用戶角色:root userAdminAnyDatabase:有分配角色和用戶的權(quán)限,但沒有查寫的權(quán)限 //這里還有幾個(gè)角色間接或直接提供了系統(tǒng)超級用戶的訪問(dbOwner 、userAdmin、userAdminAnyDatabase) 其中MongoDB默認(rèn)是沒有開啟用戶認(rèn)證的,也就是說游客也擁有超級管理員的權(quán)限。userAdminAnyDatabase:有分配角色和用戶的權(quán)限,但沒有查寫的權(quán)限添加管理員
使用命令mongo進(jìn)入命令行
創(chuàng)建第一個(gè)用戶,該用戶需要有用戶管理權(quán)限
這里設(shè)置其角色為root
use admin db.createUser({user:"root",pwd:"123456",roles:["root"]})
新增的用戶在system.users中
> db.getCollectionNames() [ "system.indexes", "system.users", "system.version" ]
第一個(gè)用戶添加完成后,便需要認(rèn)證才能繼續(xù)添加其他用戶
使用db.auth("root", "123456")認(rèn)證添加普通數(shù)據(jù)庫用戶
為其他數(shù)據(jù)庫添加用戶,添加用戶前需要切換到該數(shù)據(jù)庫
這里設(shè)置其角色為dbOwner
use db1 db.createUser({user: "db1", pwd: "123456", roles: [{ role: "dbOwner", db: "db1" }]})
查看用戶
> use admin switched to db admin > db.system.users.find()命令參考
3.1、修改用戶密碼 db.updateUser( "admin",{pwd:"password"}); 3.2、密碼認(rèn)證 db.auth("admin","password"); 3.3、MongoDB連接信息查詢 db.serverStatus().connections; MongoDB實(shí)例接受的最多連接數(shù),如果高于操作系統(tǒng)接受的最大線程數(shù),設(shè)置無效。net.maxIncomingConnections默認(rèn)(65536) 3.4、關(guān)閉MongoDB服務(wù) use admin; db.shutdownServer(); 3.5、刪除用戶 刪除用戶(需要root權(quán)限,會(huì)將所有數(shù)據(jù)庫中的football用戶刪除) db.system.users.remove({user:"football"}); 刪除用戶(權(quán)限要求沒有那么高,只刪除本數(shù)據(jù)中的football用戶) db.dropUser("football"); 3.6 查詢所有用戶 mongo 192.168.1.247/admin -u admin -p 123456 > use admin switched to db admin > db.system.users.find();啟動(dòng)報(bào)錯(cuò)解決:
在系統(tǒng)上安裝mongodb之后報(bào)錯(cuò)。
錯(cuò)誤信息:
WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘a(chǎn)lways’.We suggest setting it to ‘never’ WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘a(chǎn)lways’.We suggest setting it to ‘never’ WARNING: soft rlimits too low. rlimits set to 1024 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
解決方案:
前兩個(gè)warning echo never >> /sys/kernel/mm/transparent_hugepage/enabled echo never >> /sys/kernel/mm/transparent_hugepage/defrag 第三個(gè)warning vim /etc/security/limits.conf 添加一下幾行 * soft nofile 64000 * hard nofile 64000 mongod soft nproc 32000 mongod hard nproc 32000
重啟mongod
sudo service mongod restart
成功
重啟成功之后,所有報(bào)錯(cuò)都沒啦,如下
? ~ git:(master) mongo MongoDB shell version: 3.2.6 connecting to: test >權(quán)限說明
作為數(shù)據(jù)庫軟件,我們肯定不想誰都可以訪問,為了確保數(shù)據(jù)的安全,MongoDB 也會(huì)像其他的數(shù)據(jù)庫軟件一樣可以采用用戶驗(yàn)證的方法,那么該怎么做呢?其實(shí)很簡單,MongoDB 提供了 addUser 方法,該方法包含三個(gè)參數(shù): user - 字符串,表示用戶名 password - 字符串,對應(yīng)的密碼bushao readOnly - boolean,可選參數(shù),默認(rèn)值為 false,表示是否是只讀用戶 添加用戶:db.addUser("guest", "pass", true) 修改用戶密碼: db.addUser("guest", "newpass") 刪除用戶: db.removeUser("guest") 更復(fù)雜的使用方式請參考官方文檔。 可以將 MongoDB 的用戶分為兩類:超級用戶和數(shù)據(jù)庫用戶。超級用戶擁有最大權(quán)限,可以對所有數(shù)據(jù)庫進(jìn)行任意操作,超級用戶儲(chǔ)存在 admin 數(shù)據(jù)庫中,剛安裝的 MongoDB 中 admin 數(shù)據(jù)庫是空的;數(shù)據(jù)庫用戶存儲(chǔ)在單個(gè)數(shù)據(jù)庫中,只能訪問對應(yīng)的數(shù)據(jù)庫。另外,用戶信息保存在 db.system.users 中。 關(guān)于用戶和權(quán)限有以下特性: 數(shù)據(jù)庫是由超級用戶來創(chuàng)建的,一個(gè)數(shù)據(jù)庫可以包含多個(gè)用戶,一個(gè)用戶只能在一個(gè)數(shù)據(jù)庫下,不同數(shù)據(jù)庫中的用戶可以同名 如果在 admin 數(shù)據(jù)庫中不存在用戶,即使 mongod 啟動(dòng)時(shí)添加了 –auth 參數(shù),此時(shí)不進(jìn)行任何認(rèn)證還是可以做任何操作 在 admin 數(shù)據(jù)庫創(chuàng)建的用戶具有超級權(quán)限,可以對 MongoDB 系統(tǒng)內(nèi)的任何數(shù)據(jù)庫的數(shù)據(jù)對象進(jìn)行操作 特定數(shù)據(jù)庫比如 test1 下的用戶 test_user1,不能夠訪問其他數(shù)據(jù)庫 test2,但是可以訪問本數(shù)據(jù)庫下其他用戶創(chuàng)建的數(shù)據(jù) 不同數(shù)據(jù)庫中同名的用戶不能夠登錄其他數(shù)據(jù)庫。比如數(shù)據(jù)庫 test1 和 test2 都有用戶 test_user,以 test_user 登錄 test1 后,不能夠登錄到 test2 進(jìn)行數(shù)據(jù)庫操作
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/19361.html
摘要:需要自己手動(dòng)安裝包查詢指定軟件包的信息。而手動(dòng)安裝,必須區(qū)分包名和包全名。升級本機(jī)所有軟件包提示上邊這條命令不加最后的包名,會(huì)升級系統(tǒng)中所有的軟件包。目錄1、yum命令的查詢操作2、使用yum命令安裝服務(wù)3、使用yum命令升級服務(wù)4、使用yum命令卸載服務(wù)5、yum組管理命令(1)查詢可以安裝的軟件組(2)查詢軟件組內(nèi)包含的軟件(3)安裝軟件組(4)卸載軟件組1、yum命令的查詢操作(1)查...
閱讀 3853·2021-11-24 09:39
閱讀 1850·2021-11-02 14:41
閱讀 851·2019-08-30 15:53
閱讀 3511·2019-08-29 12:43
閱讀 1225·2019-08-29 12:31
閱讀 3117·2019-08-26 13:50
閱讀 823·2019-08-26 13:45
閱讀 1022·2019-08-26 10:56