Centos7安装redis

redis源码以及文档:https://github.com/antirez/redis
一、redis编译需要gcc,因此先安装gcc # yum install gcc
make test 需要tcl #yum -y install tcl
二、我这里安装到/user/local

#cd /usr/local
#yum install wget
#wget http://download.redis.io/releases/redis-3.2.4.tar.gz
#tar zxvf redis-3.2.4.tar.gz
#cd redis-3.2.4
#make

三、运行redis

#cd src
#./redis-server /usr/local/redis-3.2.4/redis.conf &

出现

20459:M 14 Oct 06:27:24.782 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.4 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 20459
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

20459:M 14 Oct 06:27:24.785 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
20459:M 14 Oct 06:27:24.785 # Server started, Redis version 3.2.4
20459:M 14 Oct 06:27:24.785 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
20459:M 14 Oct 06:27:24.785 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
20459:M 14 Oct 06:27:24.785 * The server is now ready to accept connections on port 6379

说明启动成功
四、关闭redis#./redis-cli shutdown
五、测试redis#./redis-cli
该命令可能出错:Could not connect to Redis at 127.0.0.1:6379: Connection refused not connected>这是由于我们启动redis时候结束窗口或Ctrl+c(注意和Ctr+z、Ctrl+d的区别)终止了redis进程
可以在命令后面加&

[root@localhost src]# ./redis-cli
127.0.0.1:6379> set foo ba
OK
127.0.0.1:6379> get foo
"ba"
127.0.0.1:6379> quit
[root@localhost src]#

六、远程访问redis时可能失败,找到redis.conf把bind 127.0.0.1注释掉就可以了。
七、远程使用时候可能会报下面错误-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients.......
修改redis.conf中的protected-mode yes 为protected-mode no重启redis
八、redis可视化工具https://github.com/uglide/RedisDesktopManager
九、redis加入服务

#cd  /usr/local/redis-3.2.4/utils
[root@localhost 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]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [] /usr/local/redis-3.2.4/redis-server
Mmmmm...  it seems like you don't have a redis executable. Did you run make install yet?


报一个错误,这是加入一个软件链接

#ln -s /usr/local/redis-3.2.4/src/redis-*  /usr/local/bin/
#./install_server.sh
#service redis_6379 start(systemctl start redis_6379.service)
#ps -ef | grep redis
#service redis_6379 stop(systemctl stop redis_6379.service)

十、开机启动

#chkconfig redis_6379 on
#chkconfig redis_6379 off

基本操作 redis-cli
redis 127.0.0.1:6379> info #查看server版本内存使用连接等信息
redis 127.0.0.1:6379> client list #获取客户连接列表
redis 127.0.0.1:6379> client kill 127.0.0.1:33441 #终止某个客户端连接
redis 127.0.0.1:6379> dbsize #当前保存key的数量
redis 127.0.0.1:6379> save #立即保存数据到硬盘
redis 127.0.0.1:6379> bgsave #异步保存数据到硬盘
redis 127.0.0.1:6379> flushdb #当前库中移除所有key
redis 127.0.0.1:6379> flushall #移除所有key从所有库中
redis 127.0.0.1:6379> lastsave #获取上次成功保存到硬盘的unix时间戳
redis 127.0.0.1:6379> monitor #实时监测服务器接收到的请求
redis 127.0.0.1:6379> slowlog len #查询慢查询日志条数
(integer) 3
redis 127.0.0.1:6379> slowlog get #返回所有的慢查询日志,最大值取决于slowlog-max-len配置
redis 127.0.0.1:6379> slowlog get 2 #打印两条慢查询日志
redis 127.0.0.1:6379> slowlog reset #清空慢查询日志信息

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值