1. Install the Go environment
First go to Golang Chinese select the corresponding version of the installation package:studygolang.com/dl, copy the download linkhttps://studygolang.com/dl/golang/go1.15.12.linux-amd64.tar.gz
:cd
to/usr/local/src
:
cd /usr/local/src
Copy the code
Download the compressed package to this directory:
Wget HTTP: / / https://studygolang.com/dl/golang/go1.15.12.linux-amd64.tar.gzCopy the code
Decompress the installation package to /usr/local and get the go folder:
tar -C /usr/local- ZXVF go1.15.12. Linux - amd64. Tar. GzCopy the code
Add /usr/loacl/go/bin to PATH variable:
vi /etc/profile
# added on the last line
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
# wq Save and exit
source /etc/profile
Copy the code
Check whether the installation and configuration are successful. Check the version number:
go version
Copy the code
2. Install the mongo
2.1 Download and Installation
Again, go to the website firstwww.mongodb.com/try/downloa…Copy the download link:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.6.tgz
Enter the/usr/local/src
Download the installation package from the following directory:
Wget HTTP: / / https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.6.tgzCopy the code
Decompress the installation package to /usr/local/ :
tar -C /usr/local/ - ZXVF mongo - Linux - x86_64 - rhel70-4.4.6. TGZCopy the code
cd .. / Go to the decompressed directory and rename it:
Mv mongo - Linux - x86_64 - rhel70-4.4.6 / mongoCopy the code
The MongoDB executable is in the bin directory, so you can add it to the PATH:
vi /etc/profile
# added on the last line
export PATH=/usr/local/mongodb/bin:$PATH
# wq Save and exit
source /etc/profile
Copy the code
Create database folder and log folder under /usrl/local/mongodb:
mkdir data
mkdir logs
Copy the code
/usrl/local/mongodb /usrl/local/mongodb
mkdir etc
cd ./etc
vi mongodb.conf
Copy the code
dbpath=/usr/local/mongodb/data
logpath=/usr/local/mongodb/logs/mongodb.log
port=27017
Copy the code
If you need to remotely connect to the MongoDB server, set bind_ip to 0.0.0.0, indicating that all IP connections are accepted. Otherwise, the default value is 127.0.0.1.
Finally, start the MongoDB service from the background:
mongod --config /usr/local/mongodb/etc/mongodb.conf --fork
Copy the code
When you connect to the MongoDB service for the first time, you do not need a password, and there is no user. You can directly enter the MongoDB service using shell commands and execute commandsmongo
You can:
2.2 Enabling Permission Authentication
To set the password, select the admin database and run the following commands. You can flexibly configure the account, password, role, and the database to which the role belongs as required. In this case, you have set the admin user who has the permission to access all databases, the hezebin user who has the read and write permission only for the test database, and the super administrator root:
use admin
db.createUser({user:"admin".pwd:"admin",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})
db.createUser({user:'hezebin'.pwd:'123456',roles:[{role:'readWrite',db:'test'}]})
db.createUser({user:'root'.pwd:'root',roles:[{role:'root',db:'admin'}]})
Copy the code
Note: It can be used after adding usersshow users
或 db.system.users.find()
View existing users.
For more details on MongoDB permissions and roles, see my other blog post, Mongodb4.x Installation and Configuration and Password Settings > 4. Login authentication
After adding admin users, disable the MongoDB service and enable MongoDB again using permission. Do not kill the MongoDB process directly (if you do, please delete the mongo.lock file in the data/db directory). You can shut it down using db.shutdownServer() in the Mongo client.
Start MongoDB with permission:
mongod --config /usr/local/mongodb/etc/mongodb.conf --auth --fork
Copy the code