1. 程式人生 > >redis多實例+MongoDB基本配置+LDAP+SVN

redis多實例+MongoDB基本配置+LDAP+SVN

redis MongoDB LDAP+SVN

redis多實例

[root@localhost redis-stable]# cp -p redis.conf redis6380.conf (拷貝出一個配置文件)

[root@localhost redis-stable]# grep 6380 redis6380.conf (參數修改,按需求修改)
port 6380
pidfile /var/run/redis_6380.pid
dbfilename dump6380.rdb
appendfilename "appendonly6380.aof"
# cluster-announce-bus-port 6380

[root@localhost redis-stable]# redis-server redis6380.conf (啟動方式)
2161:C 29 May 20:41:38.275 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2161:C 29 May 20:41:38.276 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=2161, just started
2161:C 29 May 20:41:38.276 # Configuration loaded
[root@localhost redis-stable]# ps -ef|grep redis
root      2162     1  0 20:41 ?        00:00:00 redis-server 127.0.0.1:6380
root      2167  1858  0 20:41 pts/1    00:00:00 grep redis

今天來講MongoDB的基本知識

按需求下載MongoDB

[root@localhost conf]# getenforce 
Permissive
[root@localhost conf]# service iptables status
iptables: Firewall is not running.

[root@localhost mulu]# tar -xf mongodb-linux-x86_64-rhel62-4.0.0-rc0.tgz (解壓預編譯包)

[root@localhost mulu]# ln -s mongodb-linux-x86_64-rhel62-4.0.0-rc0 mongo(軟鏈接,方便操作)

monMongoDB啟動方式
[root@localhost mongodb-linux-x86_64-rhel62-4.0.0-rc0]# mongod --dbpath data --logpath log/mongodb.log --logappend --pidfilepath pid/mongodb.pid &   (命令行啟動)

[root@localhost mulu]# cd mongo
[root@localhost mongo]# ls
bin  conf  data  GNU-AGPL-3.0  log  MPL-2  pid  README  THIRD-PARTY-NOTICES  (除了bin目錄,其他都是自己指定創建的目錄)
[root@localhost mongo]# cd conf/
[root@localhost conf]# ls
mongodb.cnf
[root@localhost conf]# cat mongodb.cnf 
dbpath=/opt/mulu/mongo/data 
logpath=/opt/mulu/mongo/log/mongodb.log
logappend=true
pidfilepath=/opt/mulu/mongo/pid/mongodb.pid
port=27017

[root@localhost conf]# mongod -f mongodb.cnf &(文件啟動)

MongoDB進去方式
[root@localhost conf]# mongo(直接進入本機的MongoDB,有waring的安全性問題)

MongoDB多實例
只需要將文件的參數修改即可

MongoDB安全策略
1.創建超級用戶
  > use admin
switched to db admin
> db.createUser(
... {
...     user: "adminuser",
...     pwd: "123",
...     roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
... }
... )
Successfully added user: {
    "user" : "adminuser",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        }
    ]
}

[root@localhost log]# ps -ef|grep mongodb
root      2633  1858  0 21:48 pts/1    00:00:15 mongod -f mongodb.cnf
root      2734  2523  0 22:22 pts/0    00:00:00 grep mongodb
[root@localhost log]# kill 2633 (停服務)

[root@localhost conf]# mongod -f mongodb.cnf & (重新啟動)

    > use test
switched to db test
> db.example.insert({"a":"a"})
WriteResult({ "nInserted" : 1 })
> dbs
2018-05-29T22:25:08.743+0800 E QUERY    [js] ReferenceError: dbs is not defined :
@(shell):1:1
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
test    0.000GB
> db.example.insert({"a":"b"})
WriteResult({ "nInserted" : 1 })
> db.example.insert({"a":"c"})
WriteResult({ "nInserted" : 1 })
> db.example.insert({"a":"d"})
WriteResult({ "nInserted" : 1 })
> db.example.insert({"a":"e"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
test    0.000GB(插入很多數據,然而一點量也沒增加,確認不用賬戶密碼登陸,無法操作)

[root@localhost conf]# mongod -f mongodb.cnf --auth &(帶認證的方式登陸)
[root@localhost conf]# mongo(不輸入用戶密碼)
MongoDB shell version v4.0.0-rc0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0-rc0
> show dbs
>                        (什麽都看不到)

[root@localhost conf]# mongo -u ‘adminuser‘ -p‘123‘ --authenticationDatabase "admin"(加上用戶密碼即可看到)
MongoDB shell version v4.0.0-rc0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0-rc0
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
test    0.000GB

[root@localhost conf]# mongo(第二種認證)
MongoDB shell version v4.0.0-rc0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.0-rc0
> use admin
switched to db admin
> db.auth("adminuser","123")  (這裏輸入用戶密碼)
1
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
test    0.000GB

mongodb配置主從模式

ldap+svn---這裏註意一點即可
1.在/etc/hosts文件裏面要寫上你的ip和hostname解析

redis多實例+MongoDB基本配置+LDAP+SVN