当前位置:网站首页>Deploy a mongodb single node server locally, enable auth authentication and enable oplog
Deploy a mongodb single node server locally, enable auth authentication and enable oplog
2022-06-28 00:58:00 【Ink Sky Wheel】
Purpose
Deploy one locally MongoDB Single node server , And enable the auth verification 、 Turn on oplog, For daily testing .
edition :4.0.9
Native system :MacOs
install
1、 Use curl Command to install .
# Get into /usr/local
cd /usr/local
# download
sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.9.tgz
# decompression
sudo tar -zxvf mongodb-osx-ssl-x86_64-4.0.9.tgz
# Rename it to mongodb Catalog
sudo mv mongodb-osx-x86_64-4.0.9/ mongodb
2、 hold MongoDB Directory of binary command files ( The installation directory /bin) Add to PATH In the path :
export PATH=/usr/local/mongodb/bin:$PATH
3、 Create log and data storage directory :
Data storage path :
sudo mkdir -p /usr/local/var/mongodb
Log file path :
sudo mkdir -p /usr/local/var/log/mongodb
Grant the current user read and write permissions to these two directories :
sudo chown username /usr/local/var/mongodb
sudo chown username /usr/local/var/log/mongodb
4、 Background start mongodb:
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
5、 see mongod Whether the service starts :
ps aux | grep -v grep | grep mongod
6、 After startup, we can use mongo Command to open a terminal :
$ cd /usr/local/mongodb/bin
$ ./mongo
MongoDB shell version v4.0.9
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Enable auth, Log in with password
start-up mongod After service , Use the client to log in , The first login does not require a password .
./mongo
Next, create a super user root, The password is root:
db.createUser({user:"root",pwd:"root",roles:[{"role":"userAdmin","db":"admin"},{"role":"root","db":"admin"},{"role":"userAdminAnyDatabase","db":"admin"}]})
MongoDB in built-in The roles are as follows : among built-role There are the following :
Read: Allows the user to read the specified database readWrite: Allows users to read and write to a specified database dbAdmin: Allows the user to execute administrative functions in the specified database , Like index creation 、 Delete , View statistics or access system.profile userAdmin: Allow the user to system.users A collection of written , You can find the specified database to create 、 Delete and manage users clusterAdmin: Only in admin Available in the database , Gives the user administrative rights to all sharding and copy-set related functions . readAnyDatabase: Only in admin Available in the database , Give the user read rights to all databases readWriteAnyDatabase: Only in admin Available in the database , Gives the user read and write access to all databases userAdminAnyDatabase: Only in admin Available in the database , That gives the user all the databases userAdmin jurisdiction dbAdminAnyDatabase: Only in admin Available in the database , That gives the user all the databases dbAdmin jurisdiction . root: Only in admin Available in the database . Super account , Super authority ( The super account created this time )
add --auth Parameters , restart mongo.--auth Parameters are used to control user access to database resources and operations . After enabling authorization ,MongoDB Require all clients to authenticate first , To determine the access rights of the client .
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork --auth
3. Log in with your account and password .
mongo -u root -p root localhost:27017/admin
perhaps
mongo "mongodb://root:[email protected]:27019/admin"
Single node start Oplog
MongoDB There is a data structure in the replica set schema of oplog, It stores all the change operations of the node . But a single instance does not have this structure , So single MongoDB How to start an instance oplog?
Method :
You need to start the instance in replica set mode , And in local A database or admin The database executes the script that initializes the replica set ,rs.initiate().
Start the instance as a replica set :
Start command , increase replSet='replset_name' Example :
./mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork --auth --bind_ip 0.0.0.0 --replSet='test'
stay local A database or admin The database executes the script that initializes the replica set .
grammar :
rs.initiate({ _id: "replset_name", members: [{_id:0,host:"ServerIP:MongoDBPort"}]})
Example :
rs.initiate({ _id: "test", members: [{_id:0,host:"localhost:27017"}]})
notes : After initialization , The only node in the replica set , It may be displayed as... For a short time SECONDARY or OTHER. generally speaking , Wait a minute , Will naturally return to primary, No manual intervention required .
summary
We can use curl install MongoDB Single node server , Turn on password verification , Need to open --auth Parameters . If you want to turn on oplog, You need to start the instance in replica set mode , And in local A database or admin The database executes the script that initializes the replica set ,rs.initiate().
Order one “ Fabulous or Looking at ” You'd better see !
Thank you, bosses !!!
边栏推荐
- 互联网业衍生出来了新的技术,新的模式,新的产业类型
- #795 Div.2 E. Number of Groups set *
- 哪个证券炒股开户佣金是最便宜,最安全的
- Squid代理服务器(缓存加速之Web缓存层)
- 翻译(5): 技术债务墻:一种让技术债务可见并可协商的方法
- 大尺寸导电滑环市场应用强度如何
- Customize MySQL connection pool
- 单晶炉导电滑环的应用范围和作用是什么
- Is it safe for Xiaobai in the stock market to open an account on the Internet?
- Why are cloud vendors targeting this KPI?
猜你喜欢
LabVIEW continuous sampling and limited sampling mode
electron窗口背景透明无边框(可用于启动页面)
给女朋友看的消息中间件
[Reading Abstract] what is wrong with English Reading Teaching in schools-- Empiricism and the PK of cognitive science
[untitled]
Software engineering job design (1): [personal project] implements a log view page
Leetcode 720. The longest word in the dictionary
Logging log usage
Matlb| improved forward push back method for solving power flow of low voltage distribution network
Redis主从复制、哨兵模式、集群的概述与搭建
随机推荐
Request object, response object, session object
Alchemy (9): simple but not simple, never-ending test -- always_ run
Is it safe to open a stock account online now? Select a listed securities firm, and the fastest time to open an account is 8 minutes
JVM的内存模型简介
Is it reliable to invest in exchange traded ETF funds? Is it safe to invest in exchange traded ETF funds
云厂商为什么都在冲这个KPI?
Mysql database tourism management system_ Jsp+mysql tourism management system based on SSM [easy to understand]
Informatics Olympiad all in one 1359: enclosed area
LabVIEW continuous sampling and limited sampling mode
Differences and functions between intranet IP and public IP
Why are cloud vendors targeting this KPI?
信息学奥赛一本通 1359:围成面积
1696D. Permutation Graph 思维
Acwing game 57 [unfinished]
券商买股票用什么app是比较好的,比较安全的
How many securities companies can a person open an account? Is it safe to open an account
Alchemy (8): parallel development and release
Translation (4): matching rules for automatic text completion
Cloud native O & M article plan
FB、WhatsApp群发消息在2022年到底有多热门?