下载安装包
tar zxvf redis-3.2.9.tar.gz
cd redis-3.2.9
make
make test & make install
cp utils /usr/local
直接在解压目录执行
./install_server.sh
[root@zhu4 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] 7000
Please select the redis config file name [/etc/redis/7000.conf]
Selected default - /etc/redis/7000.conf
Please select the redis log file name [/var/log/redis_7000.log]
Selected default - /var/log/redis_7000.log
Please select the data directory for this instance [/var/lib/redis/7000]
Selected default - /var/lib/redis/7000
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 7000
Config file : /etc/redis/7000.conf
Log file : /var/log/redis_7000.log
Data dir : /var/lib/redis/7000
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/7000.conf => /etc/init.d/redis_7000
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
vim /etc/init.d/redis_7000 将下边的三行 复制到上面
chkconfig redis_7000 on --level 2345
chkconfig redis_7000 --list
redis_7000 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@zhu4 utils]# /etc/init.d/redis_7000 start
Starting Redis server...
[root@zhu4 utils]#
[root@zhu4 utils]# /etc/init.d/redis_7000 status
Redis is running (25648)
客户端连接方式
/usr/local/bin/redis-cli -p 7000 本地连接
/usr/local/bin/redis-cli -h 127.0.0.1 -p 7000 此处的IP需要在配置文件中匹配到才可以 bind 127.0.0.1
/usr/local/bin/redis-cli -h 192.168.1.55 -p 7000 此处的IP需要在配置文件中匹配到才可以 bind 192.168.1.55
如果redis设置有密码 则需要连接进去后 执行以下操作
auth 密码 (密码在配置文件中设置) 之后便可以采取相应操作
set key1 value1
get key1
value1
或者在连接的时候加上 -a 参数
/usr/local/bin/redis-cli -h 192.168.1.55 -p 7000 -a redis(你的密码,这里我的密码为redis)
连接进去后 输入info可以获取更详细的信息
或者在连接的时候加上 info
/usr/local/bin/redis-cli -h 192.168.1.55 -p 7000 info
ls /etc/redis/7000.conf 配置文件
[root@zhu4 utils]# redis-server -h 帮助命令
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>
Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose
Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel
/etc/init.d/redis_7000 start|stop|status|restart 启动命令
或者 redis-server /etc/init.d/redis_7000 方式启动
redis-cli -p 7000 shutdown 把 7000端口的redis停止
默认数据库为16个(从0开始,0-15),默认的数据库就为0
redis的监控
-Sentinel
Sentinel 是redis自带的工具,它可以对redis主从复制进行监控,并实现主挂掉后的自动故障转移
,在转移的过程中,它还可以被配置去执行一个用户自定义脚本,在脚本中我们就能够实现报警通知等功能
cp /opt/package/redis-3.2.9/sentinel.conf /etc/redis/
/usr/local/bin/redis-sentinel -h 帮助文档
redis-server /etc/redis/sentinel.conf --sentinel