服务端redis 安装以及配置

来源:互联网 发布:sap hana sql 编辑:程序博客网 时间:2024/06/05 14:45

环境  Ubuntu vmware

1、下载redis 

登录redis官网获取下载链接

打开终端 使用如下命令下载redis压缩包

wget + 压缩包地址

2、解压

tar zxvf redis-*.tar.gz

3、编译

进入解压后的redis目录使用如下命令

make

4、安装到指定路径

make PREFIX=/usr/local/redis install

5、拷贝配置文件

将解压目录中的redis.conf配置文件拷贝到安装目录中的redis下

cp redis解压目录中配置文件位置 安装redis目录

6、编辑配置文件

daemonize no 设置为 yes

ps:只读模式修改

chmod a+w 文件名

7、加载配置文件并启动redis

./bin/redis-server ./redis.conf

8、停止redis

 ./bin/redis-cli shutdown

9、日志配置
redis默认不会保存日志,异常的时候会在控制台输出一个简单的错误堆栈信息
编辑redis.conf文件,定位到logfile属性,在后面的""中填上你的日志路径
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile "/home/liupan/redis/redis/bin/redis.log"
备注:
关闭redis的时候可能会报错,查看日志文件详细信息
30145:M 25 Oct 11:22:53.681 # User requested shutdown...
30145:M 25 Oct 11:22:53.681 * Saving the final RDB snapshot before exiting.
30145:M 25 Oct 11:22:53.682 # Failed opening the RDB file dump.rdb (in server root dir /home/liupan/redis/redis/bin) for saving: Permission denied
30145:M 25 Oct 11:22:53.682 # Error trying to save the DB, can't exit.
大意是关闭redis的时候会保存一个dump文件,而你的redis可执行文件不能在bin目录下新建一个dump文件。
解决方法:
1、使用管理员角色来启动redis
sudo ./redis-server ./redis.conf
2、更改bin文件夹的权限(有点坑,更改bin目录下的所有文件的用户名用户组一点用都没有,因为bin文件夹归属是root,你用当前用户跑的redis根本不能再root文件夹下新建dump文件)
chown 用户:用户组 bin/
个人推荐第二种,Ubuntu无法以root身份登录,每次执行都要sudo一下



原创粉丝点击