redis多实例
[[email protected] redis-stable]# cp -p redis.conf redis6380.conf (拷贝出一个配置文件)
[[email protected] 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
[[email protected] 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
[[email protected] 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的基本知识
[[email protected] conf]# getenforce
Permissive
[[email protected] conf]# service iptables status
iptables: Firewall is not running.
[[email protected] mulu]# tar -xf mongodb-linux-x86_64-rhel62-4.0.0-rc0.tgz (解压预编译包)
[[email protected] mulu]# ln -s mongodb-linux-x86_64-rhel62-4.0.0-rc0 mongo(软链接,方便操作)
monMongoDB启动方式
[[email protected] mongodb-linux-x86_64-rhel62-4.0.0-rc0]# mongod --dbpath data --logpath log/mongodb.log --logappend --pidfilepath pid/mongodb.pid & (命令行启动)
[[email protected] mulu]# cd mongo
[[email protected] mongo]# ls
bin conf data GNU-AGPL-3.0 log MPL-2 pid README THIRD-PARTY-NOTICES (除了bin目录,其他都是自己指定创建的目录)
[[email protected] mongo]# cd conf/
[[email protected] conf]# ls
mongodb.cnf
[[email protected] 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
[[email protected] conf]# mongod -f mongodb.cnf &(文件启动)
MongoDB进去方式
[[email protected] 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"
}
]
}
[[email protected] 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
[[email protected] log]# kill 2633 (停服务)
[[email protected] 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(插入很多数据,然而一点量也没增加,确认不用账户密码登陆,无法操作)
[[email protected] conf]# mongod -f mongodb.cnf --auth &(带认证的方式登陆)
[[email protected] 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
> (什么都看不到)
[[email protected] 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
[[email protected] 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
ldap+svn---这里注意一点即可
1.在/etc/hosts文件里面要写上你的ip和hostname解析
原文地址:http://blog.51cto.com/13293172/2121966
时间: 2024-10-09 02:07:13