pull/561/head
Mr Chen 1 year ago
parent 54a6a121ac
commit c4bc66e410
  1. 5
      plugins/mongodb/config/mongodb.conf
  2. 61
      plugins/mongodb/index.py

@ -7,10 +7,13 @@ processManagement:
security: security:
authorization: disabled authorization: disabled
javascriptEnabled: false javascriptEnabled: false
keyFile: {$SERVER_PATH}/mongodb/mongodb.key
storage: storage:
dbPath: {$SERVER_PATH}/mongodb/data dbPath: {$SERVER_PATH}/mongodb/data
directoryPerDB: true directoryPerDB: true
systemLog: systemLog:
destination: file destination: file
logAppend: true logAppend: true
path: {$SERVER_PATH}/mongodb/logs/mongodb.log path: {$SERVER_PATH}/mongodb/logs/mongodb.log
replication:
oplogSizeMB: 2048

@ -191,7 +191,7 @@ def mongdbClient():
auth = getConfAuth() auth = getConfAuth()
mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root')
# print(auth)
if auth == 'disabled': if auth == 'disabled':
client = pymongo.MongoClient(host='127.0.0.1', port=int(port), directConnection=True) client = pymongo.MongoClient(host='127.0.0.1', port=int(port), directConnection=True)
else: else:
@ -204,6 +204,11 @@ def mongdbClient():
def initDreplace(): def initDreplace():
mg_key = getServerDir() + "/mongodb.key"
if not os.path.exists(mg_key):
mw.execShell("openssl rand -base64 741 >> "+mg_key)
mw.execShell("chmod 600 "+mg_key)
file_tpl = getInitDTpl() file_tpl = getInitDTpl()
service_path = os.path.dirname(os.getcwd()) service_path = os.path.dirname(os.getcwd())
@ -307,7 +312,7 @@ def saveConfig():
d['systemLog']['path'] = args['log'] d['systemLog']['path'] = args['log']
d['processManagement']['pidFilePath'] = args['pid_file_path'] d['processManagement']['pidFilePath'] = args['pid_file_path']
setConfig(d) setConfig(d)
reload() restart()
return mw.returnJson(True,'设置成功') return mw.returnJson(True,'设置成功')
def initMgRoot(password='',force=0): def initMgRoot(password='',force=0):
@ -896,17 +901,6 @@ def setDbAccess():
mg_pass = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') mg_pass = pSqliteDb('config').where('id=?', (1,)).getField('mg_root')
# user_rules = [
# {'role': 'root', 'db': 'admin'},
# {'role': 'clusterAdmin', 'db': 'admin'},
# {'role': 'readAnyDatabase', 'db': 'admin'},
# {'role': 'readWriteAnyDatabase', 'db': 'admin'},
# {'role': 'userAdminAnyDatabase', 'db': 'admin'},
# {'role': 'dbAdminAnyDatabase', 'db': 'admin'},
# {'role': 'userAdmin', 'db': 'admin'},
# {'role': 'dbAdmin', 'db': 'admin'}
# ]
user_roles = [] user_roles = []
select_role = select.split(',') select_role = select.split(',')
for role in select_role: for role in select_role:
@ -954,31 +948,20 @@ def test():
# import pymongo # import pymongo
# from pymongo import ReadPreference # from pymongo import ReadPreference
# client = mongdbClient() client = mongdbClient()
db = client.admin
# db = client.admin
mg_pass = mw.getRandomString(10)
# print(db['users']) config = {
# r = db.command("grantRolesToUser", "root", '_id': 'test',
# roles=["root"]) 'members': [
# print(r) {'_id': 0, 'host': '127.0.0.1:27019'},
# users_collection = db['users'] {'_id': 1, 'host': '127.0.0.1:27017'},
# print(users_collection) ]
}
# mg_pass = mw.getRandomString(10)
# r = db.command("createUser", "root1", pwd=mg_pass, roles=["root"])
# print(r)
# config = {
# '_id': 'test',
# 'members': [
# # 'priority': 10
# {'_id': 0, 'host': '154.21.203.138:27017'},
# {'_id': 1, 'host': '154.12.53.216:27017'},
# ]
# }
# rsStatus = client.admin.command('replSetInitiate',config) rsStatus = client.admin.command('replSetInitiate',config)
# print(rsStatus) print(rsStatus)
# 需要通过命令行操作 # 需要通过命令行操作
# rs.initiate({ # rs.initiate({
@ -986,12 +969,12 @@ def test():
# members: [ # members: [
# { # {
# _id: 1, # _id: 1,
# host: '154.21.203.138:27017', # host: '127.0.0.1:27019',
# priority: 2 # priority: 2
# }, # },
# { # {
# _id: 2, # _id: 2,
# host: '154.12.53.216:27017', # host: '127.0.0.1:27017',
# priority: 1 # priority: 1
# } # }

Loading…
Cancel
Save