If there is no pagoda panel, install the pagoda panel first
Click me to view the installation tutorial
Open the app store of the pagoda panel and search for mongodb
Install mongodb and wait for the installation to complete
After the installation is complete, you need to configure it. You need to set bindip to 0.0.0.0, otherwise you can only connect locally on the server, and you cannot connect to the database remotely.
After the installation is complete, you need to close the firewall of the pagoda panel or release the port 27017 corresponding to mongodb
After Pagoda closes the firewall, it needs to release the corresponding port 27017 in the background of Alibaba Cloud or Tencent Cloud. The method of release can be found in Baidu Tutorial
test connection
Connection command:
mongo mongodb://你的公网ip:27017
You need to have a mongodb environment locally
If the following prompt appears, it means that the connection is successful, indicating that the mongodb installation of the server is successful
Set up a login account for the database below
You can see that when we connected to the mongodb of the server just now, we did not enter the user name and password. We only need to know your public network ip to connect, because the general port of the mongodb database is 27017, and others only need to know your ip, which is equivalent to We have all mongodb permissions, so we need to set a username and password for mongodb, and enable login verification
Step 1: Open the command line of the server and connect to mongodb
Step 2: Enter the admin database
Enter
use admin
the command to enter the admin database
Step 3: Create admin user
The command to create a user:
db.createUser({user: "root",pwd: "password", roles: [ { role: "root", db: "admin" } ]})
user: is the username you will use to connect to the database
password: is the password you will use to connect to the database
Step 4: Create root user
Step 5: Check whether the creation is successful, these two users must be created
Enter the command:
show users
if the following prompt appears, it means the creation is successful
Step 6: Enable user authentication
Go back to the pagoda panel, open the mongodb settings, modify the configuration file to enable user authentication
At this point the configuration is complete
The path to connect to the database:
mongodb://用户名:密码@你的服务器ip:27017/你的数据库?authSource=admin
Username: the username you just created
Password: the password you just created
your server ip: your server ip
your database: the database you want to connect to
?authSource=admin: verify the database, specify Authenticate users from that database, because we created it in the admin table so =admin