1.源码安装所依赖的包(gcc)
4.0.9版本:wget http://download.redis.io/releases/redis-4.0.9.tar.gz
yum -y install gcc
2.解压
tar -zxvf redis-4.0.8.tar.gz
3.安装
make && make install
4.初始配置
./utils/install_server.sh
[root@npaiengine-2 /data/redis-4.0.8]# ./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/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
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/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
5.常用操作
查看服务状态(默认端口6379)
netstat -utnlp | grep 6379
停止服务
/etc/init.d/redis_6379 stop
启动服务
/etc/init.d/redis_6379 start
连接Redis服务,h服务IP地址,p为服务端口,a为密码,生产环境一般不设置密码
redis-cli -h 127.0.0.1 -p 6379 -a 123456
6.连接
redis报错:bash: redis-cli: command not found...
解决方法如下:sudo cp src/redis-cli /usr/local/bin/
将redis-cli拷贝到bin下,让redis-cli指令可以在任意目录下直接使用 这样就可以解决了
7.停止服务并退出
shutdown
exit
8.配置文件解释
配置分类
名称 说明
NETWORK 网络
GENERAL 常规
SNAPSHOTTING 快照
REPLICATION 复制
SECURITY 安全
CLIENTS 客户端
MEMORY MANAGEMENT 内存管理
常用配置
vim /etc/redis/6379.conf
70 bind 192.168.4.50 #修改登录ip地址
93 port 6379 #修改端口号
501 requirepass 123456 #添加密码
187 databases 16 #修改数据库个数
137 daemonize yes #守护程序运行方式
172 logfile /var/log/redis_6379.log #日志文件位置
533 maxclienes 10000 #并发连接数量
264 dir /var/lib/redis/6379 #数据库目录
9.常用服务管理
启动服务
/etc/init.d/redis_6379 start
停止服务
/etc/init.d/redis_6379 stop
查看进程
ps -C redis-server
查看端口
netstat -nutlp | grep redis-server
10.连接服务
redis-cliping #基本测试
PONG
set name bob #存数据
get name #取数据
"bob"
exit #断开连接
11.常用命令
命令 注释
set key名 key值 储存一个Key值
maset key名列表 储存多个Key值
get key名 获取Key值
mget 储存多个Key值
select 数据库编号 0-15 切换库
keys * 显示所有Key名
keys a? 显示指定Key名
exists key名 测试Key名是否存在
ttl key 查看Key生存时间
type key 查看Key类型
move key名 库编号 移动到指定的库
expire key名 数字 设置key有效时间
del key名 删除指定的Key
flushall 删除内存里所有的Key
flushdb 删除所在库的所有Key
save 保存所有Key到硬盘
shutdown 停止服务
12.当修改IP地址以及端口号之后出现无法使用自带脚本停止服务的情况
/etc/init.d/redis_6379 stop
Stopping ...
Could not connect to Redis at 127.0.0.1:6350: Connection refused
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
解决方法如下
在退出redis服务时直接使用shutdown
shutdown
直接修改自带脚本(第43行)
vim +43 /etc/init.d/redis_6379
43 $CLIEXEC -h ip地址 -p 端口号 -a 密码 shutdown
-
« 上一篇:
88.mysql安装
-
90.k8s安装实践
:下一篇 »