欢迎投稿

今日深度:

NoSQL数据库redis安装使用,nosqlredis安装使用

NoSQL数据库redis安装使用,nosqlredis安装使用


认识Redis

REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统。

Redis是一个开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

它通常被称为数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Map), 列表(list), 集合(sets) 和 有序集合(sorted sets)等类型。

windows下安装测试:

下载地址https://github.com/MSOpenTech/redis/releases

Redis 支持 32 位和 64 位。这个需要根据你系统平台的实际情况选择,这里我们下载 Redis-x64-xxx.zip压缩包到 C 盘,解压后,将文件夹重新命名为 redis。

打开一个 cmd 窗口 使用cd命令切换目录到 C:\redis 运行 redis-server.exe redis.windows.conf 。

如果想方便的话,可以把 redis 的路径加到系统的环境变量里,这样就省得再输路径了,后面的那个 redis.windows.conf 可以省略,如果省略,会启用默认的。
这时候另启一个cmd窗口,原来的不要关闭,不然就无法访问服务端了。

切换到redis目录下运行 redis-cli.exe -h 127.0.0.1 -p 6379 。

设置键值对 set myKey abc

取出键值对 get myKey 

以下为redhat enterprise lease 6.5 版本的安装使用

1. 下载解压安装

[root@rhel65-lockey3 ~]# wget http://download.redis.io/releases/redis-4.0.1.tar.gz
[root@rhel65-lockey3 ~]# tar -axvf redis-4.0.1.tar.gz
[root@rhel65-lockey3 ~]# cd redis-4.0.1
[root@rhel65-lockey3 redis-4.0.1]# make && make install
[root@rhel65-lockey3 redis-4.0.1]# cd utils/
[root@rhel65-lockey3 utils]# ./install_server.sh ##一路回车即可

2. 设置所有端口的监听

[root@rhel65-lockey3 utils]# cat /etc/redis/6379.conf | grep bind

# By default, if no "bind" configuration directive is specified, Redis listens
# the "bind" configuration directive, followed by one or more IP addresses.
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
# internet, binding to all the interfaces is dangerous and will expose the
# following bind directive, that will force Redis to listen only into
bind 0.0.0.0####

[root@rhel65-lockey3 utils]# /etc/init.d/redis_6379 restart

3. 主从设置

在另外一台主机上安装redis然后修改配置

[root@rhel65-lockey4 utils]# cat /etc/redis/6379.conf | grep slaveof

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
slaveof 172.25.5.93 6379#######

[root@rhel65-lockey4 utils]# /etc/init.d/redis_6379 restart

4. 验证

master端

slave端

redis主从高可用

172.25.5.93 初始master
172.25.5.94 slaver
172.25.5.95 slaver

vim /etc/redis/sentinel.conf#修改部分如下,修改完成将此文件在三台主机之间同步

[root@rhel65-lockey4 bin]# sed -n ‘/#/!p’ /etc/redis/sentinel.conf

bind 0.0.0.0
protected-mode no

sentinel monitor mymaster 172.25.5.93 6379 2

sentinel down-after-milliseconds mymaster 20000

sentinel failover-timeout mymaster 100000

在三台主机中执行以下命令:

/usr/local/bin/redis-server /etc/redis/sentinel.conf --sentinel

初始master端的显示


172.25.5.94

172.25.5.95

在172.25.5.93上执行以下命令

然后就会看到主从切换了:

注意对于shutdown掉的主机,如果需要重新加入主从设置的话需要修改以下内容然后重起:

vim /etc/redis/6379.conf

slaveof 172.25.5.95 6379#ip是切换后的主机

www.htsjk.Com true http://www.htsjk.com/redis/26285.html NewsArticle NoSQL数据库redis安装使用,nosqlredis安装使用 认识Redis REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统。Redis是一个开源的使用ANSI C语言编写、遵守BSD协议、支持网络...
相关文章
    暂无相关文章
评论暂时关闭