Redis 基本数据类型及其使用

作者:Rui 发布时间:June 7, 2016 分类:BIGDATA,Redis 浏览:741

Redis 提供丰富的数据类型,方便了开发者使用,它的数据类型包括strings,hashs,lists,sets,sort sets,以及bitmaps,hyperloglogs,Redis 3.2 之后,又添加了Geo Index的数据类型,专门存储地理坐标信息,并提供了相关的命令来检索地理坐标。

Redis Keys

Redis的key 是一个二进制安全的字符串,也就是你可以使用二进制串当做key,空字符串也可以当做key。
设置key值时,需要注意一下几点:

  1. Key不易过长,最好不要超过1024 bytes,因为当检索key是需要对key进行比对,如果key较大,比对就相对比较耗时,带来性能问题
  2. Key 也不易过短,简单易读最好,例如:user:1000:flowers
  3. Key 取值最好有一个模式,例如:object-type:id
  4. Redis 允许的最大key值为512MB

因为Redis是单线程模式,所有命令都是按队列顺序执行,所以每个命令的执行速度对Redis的性能影响也是比较明显的,所以建议大家在使用时,尽可能使用简洁明了的key

阅读剩余部分...

Redis protected-mode

作者:Rui 发布时间:June 6, 2016 分类:BIGDATA,Redis 浏览:10,244

Redis protected-mode 是3.2 之后加入的新特性,在Redis.conf的注释中,我们可以了解到,他的具体作用和启用条件

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes

可以看到 Protected-mode 是为了禁止公网访问redis cache,加强redis安全的。

它启用的条件,有两个:
1) 没有bind IP
2) 没有设置访问密码

如果启用了,则只能够通过lookback ip(127.0.0.1)访问Redis cache,如果从外网访问,则会返回相应的错误信息:

(error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the lookback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the --portected-mode no option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

Centos yum源替换为阿里云源

作者:Rui 发布时间:June 2, 2016 分类:Linux,CLOUD 浏览:605

备份系统原镜像文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS 6

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

运行yum makecache生成缓存

yum clean all
yum makecache

Can not remove file Operation not permitted

作者:Rui 发布时间:June 1, 2016 分类:Linux,CLOUD 浏览:478

使用chattr命令解锁文件后,可删除,请参考以下命令:

chattr -i /home/wwwroot/yoursite/.user.ini

chattr 命令:通过chattr命令,可以修改文件属性,锁定文件,增加系统安全性。通常有一些文件,系统管理员也无法删除修改。都是通过该命令锁定了该文件。

语法:

chattr [-RV] [+-=AacDdijsSu] [-v version] 文件目录

参数描述:

-R  递归处理文件
-V  详细显示修改内容
+   激活属性
-   失效属性
=   指定属性
A   告诉系统不要修改该文件的最后时间
S   一旦系统修改了该文件,立即同步到硬盘
a   Append Only
i   系统不允许任何对该文件的修改
D   检查压缩文件中的错误
d   No  Dump 在对文件备份时,忽略该文件
C   compress 系统以透明的方式压缩这个文件
s   Secure Delete 让系统删除该文件时,使用0填充文件所在区域
u   Un Delete  当系统请求删除该文件时,系统会保留其数据块,以便以后能够恢复