标签:公网 设置 hash 1.2 bbb second cut 保存数据 权限
[toc][root@xavi ~]# cd /usr/local/src/redis-4.0.9
[root@xavi redis-4.0.9]# redis-cli
127.0.0.1:6379> set key1 xavi
OK
127.0.0.1:6379> set key2 xavilinux
OK
127.0.0.1:6379> set key1 linux
OK
127.0.0.1:6379> get key1
"linux"
127.0.0.1:6379> SETNX key1 aaa
(integer) 0
127.0.0.1:6379> get key1
"linux"
127.0.0.1:6379> SETNX key3 aaa
(integer) 1
127.0.0.1:6379> get key3
"aaa"
127.0.0.1:6379> set key3 aaa ex 10
OK
127.0.0.1:6379> get key3
(nil)
127.0.0.1:6379> set key3 aaa ex 100
OK
127.0.0.1:6379> get key3
"aaa"
set key1 aming//第二次赋值会覆盖
setnx key2 aaa //返回1 如果key2不存在直接创建key
setnx key2 bbb //返回0,如果key2存在,返回0
setex key3 10 1 //给key3设置过期时间为10s,值为1,若key已经存在,会覆盖新的值
127.0.0.1:6379> LPUSH list aaa
(integer) 1
127.0.0.1:6379> LPush list bbb
(integer) 2
127.0.0.1:6379> LPUSH list ccc
(integer) 3
127.0.0.1:6379> LPUSH list ddd
(integer) 4
127.0.0.1:6379> LRANGE list 0 -1
1) "ddd"
2) "ccc"
3) "bbb"
4) "aaa"
127.0.0.1:6379> RPOP list
"aaa"
127.0.0.1:6379> lpop list
"ddd"
[ ] linsert lista before 2 3 //aaa 333//在aaa的前面插入一个元素为333
举例:
127.0.0.1:6379> linsert list before aaa bbb
(integer) 3
127.0.0.1:6379> linsert list after aaa 111
(integer) 4
127.0.0.1:6379> lrange list 0 -1
1) "bbb"
2) "aaa"
3) "111"
4) "ccc"
127.0.0.1:6379> lindex list 0 //LINDEX 查看元素的值
"bbb"
127.0.0.1:6379> llen list // LINDEX 查看元素的长度
(integer) 4
127.0.0.1:6379> sadd setb 222
(integer) 1
127.0.0.1:6379> sadd setb aaa
(integer) 1
127.0.0.1:6379> sadd seta 111
(integer) 1
127.0.0.1:6379> smembers seta
1) "bbb"
2) "111"
127.0.0.1:6379> smembers setb
1) "aaa"
2) "222"
127.0.0.1:6379> sdiff seta setb
1) "bbb"
2) "111"
127.0.0.1:6379> ZADD zseta 11 123
(integer) 1
127.0.0.1:6379> ZADD zseta 0 1ab
(integer) 1
127.0.0.1:6379> zrange zseta 0 -1
1) "1ab"
2) "123"
127.0.0.1:6379> ZADD zseta 14 dddd
(integer) 1
127.0.0.1:6379> zadd zseta 16 121211
(integer) 1
127.0.0.1:6379> zrange zseta 0 -1
1) "1ab"
2) "123"
3) "dddd"
4) "121211" //显示所有元素,按顺序显示
127.0.0.1:6379> ZREM zseta 123 //删除指定元素
(integer) 1
127.0.0.1:6379> ZRANGE zseta 0 -1
1) "1ab"
2) "dddd"
3) "121211"
127.0.0.1:6379> zrange zseta 0 -1
1) "1ab"
2) "123"
3) "dddd"
4) "121211"
127.0.0.1:6379> zrank zseta dddd
(integer) 2 //返回元素的索引值,索引值从0开始,按score正向排序
127.0.0.1:6379> ZREVRANK zseta 121211
(integer) 0 //按score反向排序,获取数据的值
127.0.0.1:6379> ZCARD zseta
(integer) 4
ZCOUNT 统计范围内集合元素的个数
127.0.0.1:6379> ZCOUNT zseta 10 20
(integer) 3 //返回分值范围10-20的元素个数
(integer) 2
127.0.0.1:6379> ZRANGEBYSCORE zseta 10 20
1) "123"
2) "dddd"
3) "121211"
127.0.0.1:6379> ZREMRANGEBYSCORE zseta 10 15
(integer) 2
127.0.0.1:6379> ZRANGE zseta 0 -1
1) "1ab"
2) "121211"
127.0.0.1:6379> ZRANGE zseta 0 -1
1) "asdaqwe"
2) "123"
3) "234"
4) "345"
5) "asdaa"
6) "asasdz"
127.0.0.1:6379> ZREMRANGEBYRANK zseta 1 10
(integer) 5
127.0.0.1:6379> ZRANGE zseta 0 -1
1) "asdaqwe"
127.0.0.1:6379> HMSET hash2 a 1 b 2 c 3 d 4
OK
127.0.0.1:6379> Hgetall hash2
1) "a"
2) "1"
3) "b"
4) "2"
5) "c"
6) "3"
7) "d"
8) "4"
127.0.0.1:6379> hmget hash2 b c
1) "2"
2) "3"
127.0.0.1:6379> hdel hash2 b
(integer) 1
127.0.0.1:6379> Hgetall hash2
1) "a"
2) "1"
3) "c"
4) "3"
5) "d"
6) "4"
127.0.0.1:6379> hkeys hash2
1) "a"
2) "c"
3) "d"
127.0.0.1:6379> hvals hash2
1) "1"
2) "3"
3) "4"
127.0.0.1:6379> hlen hash2
(integer) 3
127.0.0.1:6379> keys *
1) "list1"
2) "k2"
3) "list"
4) "k3"
5) "set2"
6) "hash1"
7) "hash2"
8) "zseta"
9) "mykey"
10) "key1"
11) "set3"
12) "setb"
13) "seta"
14) "key2"
15) "k1"
16) "set1"
127.0.0.1:6379> keys my*
1) "mykey"
127.0.0.1:6379> EXISTS key1
(integer) 1
127.0.0.1:6379> EXISTS key11
(integer) 0
127.0.0.1:6379> del key1
(integer) 1
127.0.0.1:6379> get key1
(nil)
127.0.0.1:6379> EXPIRE k2 10
(integer) 1
127.0.0.1:6379> get k2
"2"
127.0.0.1:6379> get k2
(nil)
127.0.0.1:6379> ttl key2
(integer) 6
127.0.0.1:6379> ttl key2
(integer) 1
127.0.0.1:6379> ttl key2
(integer) -2
127.0.0.1:6379> move set2 1
(integer) 1
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> keys *
1) "set2"
127.0.0.1:6379[1]> SELECT 0
OK
127.0.0.1:6379> EXPIRE mykey 1000
(integer) 1
127.0.0.1:6379> ttl mykey
(integer) 996
127.0.0.1:6379> rename setb set3
OK
127.0.0.1:6379> keys set*
1) "set3"
2) "seta"
3) "set1"
127.0.0.1:6379> TYPE seta
set
127.0.0.1:6379> TYPE zseta
zset
127.0.0.1:6379> type key1
none
127.0.0.1:6379> type hash2
hash
127.0.0.1:6379> type list
list
dbsize //返回当前数据库中key的数目
info//返回redis数据库状态信息
127.0.0.1:6379> DBSIZE
(integer) 11
127.0.0.1:6379> info
# Server
redis_version:4.0.9
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:5c0f8253777cfd43
redis_mode:standalone
os:Linux 3.10.0-514.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:7661
run_id:8e0a79aba2f0507ea46724b5e274a026a4b03b14
tcp_port:6379
uptime_in_seconds:20486
uptime_in_days:0
hz:10
lru_clock:2406733
executable:/usr/local/src/redis-4.0.9/redis-server
config_file:/etc/redis.conf
# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:850408
used_memory_human:830.48K
used_memory_rss:7700480
used_memory_rss_human:7.34M
used_memory_peak:872080
used_memory_peak_human:851.64K
[ ] config set dir //更改配置参数
127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/data/redis"
127.0.0.1:6379> CONFIG GET dbfileema
(empty list or set)
127.0.0.1:6379> CONFIG GET dbfilename
1) "dbfilename"
2) "dump.rdb"
前两年Redis比较火的时候,也就是×××最严重的时候。见到了很多次由Redis被黑导致系统被黑的案例!
Redis 服务启动了,但是监听了一个全网IP,如果6379默认端口没有更改,并且iptables也处于关闭,公网IP 也开放着,Redis也没有设置任何密码,×××就会扫描端口,然后就可以轻轻松松登录你的Redis服务器,并且是超级管理员的权限。然后×××就可以设置dir dbname , dir 定义到/root/.ssh 且dbname定义为:.ssh/authorized_keys 再把这个值写上自己的公钥。
这些应该都不陌生吧,这不就活生生的把×××的公钥上传到了咱们的服务器中,然后利用超级管理员做任何想做的事
打开配置文件 vim /etc/redis.conf
设置监听ip
bind 127.0.0.1 2.2.2.2//可以是多个ip,用空格分隔
设置监听端口
port 16000
设置密码
requirepass xavi
redis-cli -a ‘asd9577‘
将config命令改名
rename-command CONFIG xavi
禁掉config命令
rename-command CONFIG “”
[root@xavi redis-4.0.9]# vim /etc/redis.conf
[root@xavi redis-4.0.9]# killall redis-server
[root@xavi redis-4.0.9]# redis-server /etc/redis.conf //修改密码后重启redis
[root@xavi redis-4.0.9]# redis-cli
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> redis-cli -a ‘xavi>com‘
(error) ERR unknown command ‘redis-cli‘
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> quit
[root@xavi redis-4.0.9]# redis-cli -a ‘xavi>com‘
127.0.0.1:6379> keys *
(empty list or set)
标签:公网 设置 hash 1.2 bbb second cut 保存数据 权限
原文地址:http://blog.51cto.com/12995218/2132295