Justman10000

Install MongoDB

Mar 10th, 2023 (edited)
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.50 KB | None | 0 0
  1. # To see all supported OS and existing versions, go to https://www.mongodb.com/try/download/community
  2. did=debian12
  3. version=8.2.1
  4. shVersion=2.5.8
  5.  
  6. wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$did-$version.tgz
  7. gunzip mongodb-linux-x86_64-$did-$version.tgz
  8. tar xvf mongodb-linux-x86_64-$did-$version.tar
  9. mv mongodb-linux-x86_64-$did-$version /usr/local/mongodb
  10. rm -r mongodb-linux-x86_64-$did-$version.tar
  11.  
  12. mkdir /usr/local/mongodb/db
  13. chmod -R 755 /usr/local/mongodb
  14. /usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/db --bind_ip_all &
  15. echo $! > /usr/local/mongodb/pid
  16.  
  17. ln -fs /usr/local/mongodb/bin/* /usr/bin
  18.  
  19. reset
  20.  
  21. read -p 'Username: ' username
  22. read -p 'Password: ' password
  23.  
  24. [[ -z $username ]] || [[ -z $password ]] && exit
  25.  
  26. wget https://downloads.mongodb.com/compass/mongosh-$shVersion\-linux-x64-openssl3.tgz
  27. mv mongosh-2.5.8-linux-x64-openssl3/bin/mongosh /usr/bin
  28.  
  29. # Connect
  30. mongosh --port 27017 -u $username -p $password --authenticationDatabase 'admin'
  31.  
  32. # Create user
  33. ## Global perms
  34. use admin
  35. db.createUser(
  36.   {
  37.     user: $username,
  38.     pwd: $password,
  39.     roles: [ { role: "root", db: "admin" } ]
  40.   }
  41. )
  42. ## Local on a database
  43. ### db.createUser(
  44. ###   {
  45. ###     user: "USERNAME",
  46. ###     pwd: "PASS",
  47. ###     roles: [ { role: "dbOwner", db: "DB_NAME" } ]
  48. ###   }
  49. ### )
  50. # Delete user
  51. ## db.dropUser("USER_NAME")
  52.  
  53. cat << EOF > /root/.mongoshrc.js
  54. db.auth($username, $password)
  55. EOF
  56.  
  57. # To shutdown
  58. ## kill $(cat /usr/local/mongodb/db/mongod.lock)
Advertisement
Add Comment
Please, Sign In to add comment