Justman10000

Install MongoDB

Mar 10th, 2023 (edited)
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.45 KB | None | 0 0
  1. # To see all avaible os an versions, go to https://www.mongodb.com/try/download/community
  2. did=debian12
  3. version=8.0.6
  4.  
  5. wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$did-$version.tgz
  6. gunzip mongodb-linux-x86_64-$did-$version.tgz
  7. tar xvf mongodb-linux-x86_64-$did-$version.tar
  8. mv mongodb-linux-x86_64-$did-$version /usr/local/mongodb
  9. rm -r /usr/local/mongodb/LICENSE-Community.txt /usr/local/mongodb/MPL-2 /usr/local/mongodb/THIRD-PARTY-NOTICES /usr/local/mongodb/README
  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. # Connect
  27. mongosh --port 27017 -u $username -p $password --authenticationDatabase 'admin'
  28.  
  29. # Create user
  30. ## Global perms
  31. use admin
  32. db.createUser(
  33.   {
  34.     user: $username,
  35.     pwd: $password,
  36.     roles: [ { role: "root", db: "admin" } ]
  37.   }
  38. )
  39. ## Local on a database
  40. ### db.createUser(
  41. ###   {
  42. ###     user: "USERNAME",
  43. ###     pwd: "PASS",
  44. ###     roles: [ { role: "dbOwner", db: "DB_NAME" } ]
  45. ###   }
  46. ### )
  47. # Delete user
  48. ## db.dropUser("USER_NAME")
  49.  
  50. cat << EOF > .mongoshrc.js
  51. db.auth($username, $password)
  52. EOF
  53.  
  54. # To shutdown
  55. ## kill $(cat /usr/local/mongodb/db/mongod.lock)
Advertisement
Add Comment
Please, Sign In to add comment