本人以前一直用Robo連接遠(yuǎn)程數(shù)據(jù)庫(kù)管理吗跋,被黑客攻擊后(見(jiàn)文章1 逢艘、文章2)再也不敢用了蒸绩,因?yàn)槲抑鳈C(jī)linux鳞青,又嫌mongo shell敲起來(lái)太累一直對(duì)命令行不感冒...
霸饲,所以就想著找一個(gè)能跑在服務(wù)器的web端管理器。上github一搜臂拓,發(fā)現(xiàn)mongo-express星星比較多贴彼,于是就配置了一下,在服務(wù)器歡快的跑了起來(lái)埃儿,記錄如下。
- 服務(wù)器隨便找個(gè)地方建個(gè)文件夾融涣,里面運(yùn)行
npm install mongo-express
童番,注意不要按官網(wǎng)說(shuō)的全局裝,不然裝了以后位置還真不好找威鹿。 - 修改默認(rèn)配置文件:進(jìn)入
你的安裝文件夾/node_modules/mongo-express
剃斧,執(zhí)行cp config.default.js config.js
. - 編輯
config.js
文件,以下幾個(gè)地方要注意:
module.exports = {
mongodb: {
server: 'localhost',
port: 你的mongodb端口,為安全起見(jiàn)忽你,最好修改默認(rèn)端口
//ssl: connect to the server using secure SSL
ssl: process.env.ME_CONFIG_MONGODB_SSL || mongo.ssl,
//sslValidate: validate mongod server certificate against CA
sslValidate: process.env.ME_CONFIG_MONGODB_SSLVALIDATE || true,
//sslCA: array of valid CA certificates
sslCA: [],
//autoReconnect: automatically reconnect if connection is lost
autoReconnect: true,
//poolSize: size of connection pool (number of connections to use)
poolSize: 4,
//set admin to true if you want to turn on admin features
//if admin is true, the auth list below will be ignored
//if admin is true, you will need to enter an admin username/password below (if it is needed)
admin: true 或 false幼东,true為admin登錄,安全性考慮建議設(shè)為false
// >>>> If you are using regular accounts, fill out auth details in the section below
// >>>> If you have admin auth, leave this section empty and skip to the next section
auth: [
/*
* Add the name, username, and password of the databases you want to connect to
* Add as many databases as you want!
*/
{
database: '要管理的數(shù)據(jù)庫(kù)名稱',
username: '此數(shù)據(jù)庫(kù)管理員',
password: '管理員密碼',
},
],
// >>>> If you are using an admin mongodb account, or no admin account exists, fill out section below
// >>>> Using an admin account allows you to view and edit all databases, and view stats
//如果上面的admin為true,這個(gè)地方填入admin信息
adminUsername: '*******',
adminPassword: '*******',
//whitelist: hide all databases except the ones in this list (empty list for no whitelist)
whitelist: [],
//blacklist: hide databases listed in the blacklist (empty list for no blacklist)
blacklist: [],
},
site: {
// baseUrl: the URL that mongo express will be located at - Remember to add the forward slash at the start and end!
baseUrl: process.env.ME_CONFIG_SITE_BASEURL || '/',
cookieKeyName: 'mongo-express',
cookieSecret: process.env.ME_CONFIG_SITE_COOKIESECRET || 'cookiesecret',
host: process.env.VCAP_APP_HOST || '你的服務(wù)器ip地址',//這個(gè)地方弄了很久根蟹,最后搞清楚是不帶http的服務(wù)器地址
port: process.env.VCAP_APP_PORT || mongo-express 跑起來(lái)以后?端口號(hào)脓杉,默認(rèn)是8081,最好改一下,
requestSizeLimit: process.env.ME_CONFIG_REQUEST_SIZE || '50mb',
sessionSecret: process.env.ME_CONFIG_SITE_SESSIONSECRET || 'sessionsecret',
sslCert: process.env.ME_CONFIG_SITE_SSL_CRT_PATH || '',
sslEnabled: process.env.ME_CONFIG_SITE_SSL_ENABLED || false,
sslKey: process.env.ME_CONFIG_SITE_SSL_KEY_PATH || '',
},
//set useBasicAuth to true if you want to authenticate mongo-express loggins
//if admin is false, the basicAuthInfo list below will be ignored
//this will be true unless ME_CONFIG_BASICAUTH_USERNAME is set and is the empty string
useBasicAuth: process.env.ME_CONFIG_BASICAUTH_USERNAME !== '',
basicAuth: {
username: process.env.ME_CONFIG_BASICAUTH_USERNAME || 'mongo-express 登錄用戶名简逮,最好改一下',
password: process.env.ME_CONFIG_BASICAUTH_PASSWORD || 'mongo-express 登錄密碼',
},
設(shè)置好了以后球散,進(jìn)入你的安裝文件夾/node_modules/mongo-express
,執(zhí)行npm start
散庶,就跑起來(lái)了蕉堰。然后網(wǎng)頁(yè)端訪問(wèn)服務(wù)器ip:你定義的端口號(hào)
, 會(huì)提示登錄,按照你設(shè)定的用密登錄就可以管理了悲龟。
- 這樣還是有點(diǎn)麻煩屋讶,每次都要做上面這個(gè)步驟,寫個(gè)簡(jiǎn)單的shell腳本mongoadmin.sh:
cd /你的安裝文件夾/node_modules/mongo-express & npm start
賦予權(quán)限:
chmod -x mongoadmin.sh
那么每次. mongoadmin.sh
就行了须教。
還是那句話皿渗,數(shù)據(jù)庫(kù)安全無(wú)小事,所以這個(gè)用的時(shí)候打開(kāi)没卸,用完就關(guān)閉吧羹奉,另外,做好數(shù)據(jù)庫(kù)自動(dòng)備份约计,我現(xiàn)在的頻率是每天備份诀拭。