Giter VIP home page Giter VIP logo

Comments (8)

zengxc-1996 avatar zengxc-1996 commented on August 21, 2024
connection:
mongo 127.0.0.1:27017/admin -uroot -p123456

add user:
use admin
db.createUser({user:"root",pwd:"123456",roles:[{role:"readWrite",db:"admin"}]})

delete user:
db.system.users.remove({user:"root"})

from ansible-mongodb.

qiaofeng1227 avatar qiaofeng1227 commented on August 21, 2024

image

from ansible-mongodb.

qiaofeng1227 avatar qiaofeng1227 commented on August 21, 2024

mongodb4.0在ubuntu18.04下可以随机密码可以登陆,mongodb4.0在ubuntu16.04下无法用初始密码和随机密码登陆,和mongodb3.4一样。
结论:init.sh在ubuntu16.04下无法正常运行

from ansible-mongodb.

qiaofeng1227 avatar qiaofeng1227 commented on August 21, 2024

经过验证,${new_password}替换成固定字符串是可以随机密码成功的。
论据:ubuntu16.04下${new_password}以及双引号,单引号的连用可能有些差异

from ansible-mongodb.

qiaofeng1227 avatar qiaofeng1227 commented on August 21, 2024

之前上架的ubuntu16.04的mongodb3.4也是随机密码未生效的。老镜像连init.sh脚本都没有

ubuntu@ip-172-31-45-58:~$ cat /credentials/password.txt 
mongodb username:root
mongodb password:m02XeTWGAQ 

ubuntu@ip-172-31-45-58:~$ sudo su
root@ip-172-31-45-58:/home/ubuntu# cd /credentials/
root@ip-172-31-45-58:/credentials# ls
password.txt
root@ip-172-31-45-58:/credentials# ls
password.txt
root@ip-172-31-45-58:/credentials# find / -name init.sh
root@ip-172-31-45-58:/credentials# find / -name init_password.sh
root@ip-172-31-45-58:/credentials# mongodb admin -u root -p m02XeTWGAQ
No command 'mongodb' found, did you mean:
 Command 'mongod' from package 'mongodb-server' (universe)
mongodb: command not found
root@ip-172-31-45-58:/credentials# mongo admin -u root -p m02XeTWGAQ
MongoDB shell version v3.4.24
connecting to: mongodb://127.0.0.1:27017/admin
MongoDB server version: 3.4.24
2021-05-10T05:50:36.656+0000 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1461:20
@(auth):6:1
@(auth):1:2
exception: login failed
root@ip-172-31-45-58:/credentials# 

from ansible-mongodb.

qiaofeng1227 avatar qiaofeng1227 commented on August 21, 2024

老镜像没有做密码随机化,默认密码123456可以登陆。

root@ip-172-31-45-58:/credentials# mongo admin -u root -p 123456
MongoDB shell version v3.4.24
connecting to: mongodb://127.0.0.1:27017/admin
MongoDB server version: 3.4.24
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: 
2021-05-10T04:22:37.745+0000 I STORAGE  [initandlisten] 
2021-05-10T04:22:37.745+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2021-05-10T04:22:37.745+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2021-05-10T04:22:38.719+0000 I CONTROL  [initandlisten] 
2021-05-10T04:22:38.719+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2021-05-10T04:22:38.719+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2021-05-10T04:22:38.719+0000 I CONTROL  [initandlisten] 
> exit
bye

from ansible-mongodb.

zengxc-1996 avatar zengxc-1996 commented on August 21, 2024

This will change the password:

new_password=123
echo $new_password

echo "
use admin
db.changeUserPassword('root', '$new_password')
exit
" | mongo

image

Do not change the password:

new_password=$(pwgen -ncCs 15 1)
echo $new_password

echo "
use admin
db.changeUserPassword('root', '$new_password')
exit
" | mongo

image

from ansible-mongodb.

chendelin1982 avatar chendelin1982 commented on August 21, 2024

use docker to replace it

from ansible-mongodb.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.