linux下安装redis并配置

redis官网上给出了安装步骤,这里做一下总结。

1、Download, extract and compile Redis with:

wget http://download.redis.io/releases/redis-3.2.9.tar.gz
tar xzf redis-3.2.9.tar.gz
cd redis-3.2.9
make

2、配置并启动redis。

# 备份redis配置文件
cp redis.conf redis.conf.bak

a>配置reids为后台驻留程序。打开redis.conf,找到daemonize,可以看到reids默认情况下不是后台驻留程序。

# By default Redis does not run as a daemon. Use ‘yes‘ if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no# 修改成:daemonize yes

b>配置redis log文件路径。

# 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 ""# 修改为如下,意思为把log文件放在redis安装目下logs/redis.log(要自己创建好目录结构并赋予读写权限)logfile "logs/redis.log"

c>配置redis远程连接

  暂不配置

d>创建redis用户

groupadd redis
useradd -r -g redis -s /bin/false redis

e>修改redis目录拥有者为redis:redis

chown -R redis:redis ./

f>启动redis

# redis3.x
# 启动redis 禁止使用root启动!!!
# 修改redis.conf文件后需指定配置文件路径启动
sudo -u redis src/redis-server /usr/local/redis-3.2.9/redis.conf

# redis客户端连接命令
redis-cli -h 127.0.0.1 -p 6379 -a password

#

g>关闭redis

src/redis-cli shutdown

# 强制关闭redis,找到redis进程号,kill掉。
netstat -anp | grep redis
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      1132/src/redis-serv
kill -9 1132

可能遇到的问题:

1、在执行src/redis-cli shutdown时报错:“(error) ERR Errors trying to SHUTDOWN. Check logs.”。日志(上面配置了日志路径)如下:

# User requested shutdown...
* Saving the final RDB snapshot before exiting.
# Failed opening the RDB file dump.rdb (in server root dir /usr/local/redis-3.2.9) for saving: Permission denied
# Error trying to save the DB, can‘t exit.

解决方法:

You should check your redis.conf file to see the permissions in dir and dbfilename. If the file named in the dbfilename which is located in the path specified in the dir path exists and the permission is also right. then the problem should be fixed.

Hope this will help someone.

P.S.

To find the redis.conf file location, you can use the #ps ax | grep redis to check. Usually it will be passed to the redis-server as input file.

For the dir permissions:it should be 755, for the dbfilename, it should be 644

Sometimes you also need to use top command to check whether the user:group of the redis-server and the owner of dir are consistent. i.e. The redis-server is running by redis:redis, but the dir is under root:root. In this case, you need to chown redis:redis -R dir.

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff }
span.s1 { }

时间: 2024-07-31 11:12:55

linux下安装redis并配置的相关文章

Linux 下安装 Redis 服务器

本文简单介绍了 Linux 下安装 Redis 服务器的步骤,同时简要介绍服务器的配置.启动以及状态检测.另外还介绍了 32 位 CentOS 下安装 Redis 时遇到的一些问题的解决.        一. 查看 Linux 相关信息        版本查看cat /etc/issueCentOS release 5.5 (Final)        位数查看getconf LONG_BIT32        二. 安装 tcl        先装好 tcl,不然 redis 的 make t

linux 下安装redis以及php Redis扩展

1 [php] view plaincopy在CODE上查看代码片派生到我的代码片 2 linux 下安装redis以及php Redis扩展 3 4 环境配置: centos6.0 nginx/1.0.0 php/5.3.8 mysql/5.5.17 5 6 步骤一.下载redis 7 可以去http://redis.io/去下载最新版本 8 我用的是 redis 2.8.11 9 进入软件安装包存放目录: cd /var/install/software/ 10 wget http://do

linux 下安装 mysql 并配置 python 开发环境

1.安装 mysql ,安装过程中将提示设置 root 用户的密码,默认可以设置为 rootadmin . $ sudo apt-get install mysql-server 2.安装 mysql 开发工具(不安装时,安装 MySQL-python 提示错误 "mysql_config not found"). $ sudo apt-get install libmysqld-dev 3.安装 python 的 mysql 库 MySQL-python (首先安装 python-d

linux 下安装jdk及配置jdk环境图解

linux 下安装jdk及配置jdk环境图解 一:先检测是否已安装了JDK 执行命令: # rpm -qa|grep jdk  或   # rpm -q jdk  或  #find / -name jdk* /soft/openfire_java/jdk-7u40-linux-x64.rpm /usr/java/jdk1.7.0_15 /usr/java/jdk1.7.0_15/jre/lib/servicetag/jdk_header.png /usr/java/jdk1.7.0_15/lib

Linux下安装Java环境配置

1.下载安装文件 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.在usr目录下建立java安装目录 cd /usr mkdir java 3.将安装文件拷贝到java目录下,并执行解压命令 tar -zxvf jdk-8u151-linux-x64.tar.gz 4.设置环境变量 vim /etc/profile 在文件末尾添加如下内容: JAVA_HOME=/

windows下安装redis并配置外网访问

windows下安装redis已经配置外网访问 下载windows版本redis 官网无法下载windows版本的redis,需要到此链接下载https://github.com/microsoftarchive/redis/releases 选择 .msi 结尾的进行下载 双击运行,直接安装.根据提示进行安装即可.可以选择安装的端口 进入安装目录 ? 选择安装的目录(根据自己实际情况选择) ? 选择运行的端口(根据自己实际情况安装) 设置redis运行的最大内存 设置配置文件(进入安装目录)

windows和linux下安装redis

1.redis简介redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set --有序集合)和hashs(哈希类型).这些数据类型都支持push/pop.add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的.在此基础上,redis支持各种不同方式的排序.与memcached一样,为了保证效率,数据都是缓存在内存中.区别的是redis

CentOS6.8下安装redis并配置开机自启动

参考资料:http://www.bubuko.com/infodetail-1006383.html   http://www.cnblogs.com/skyessay/p/6433349.html 一.安装 下载redis-3.0.5.tar.gz [[email protected] ~]# cd /opt [[email protected] opt]# wget http://192.168.10.173:8080/website/linux/redis-3.0.5.tar.gz [[e

linux下安装redis集群(Master-Slave)

本文演示了redis在同一台linux上的安装及运行多个实例,并演示了主从复制,以及如何进行主从的切换. 1. 下载 $ wget http://download.redis.io/releases/redis-3.0.7.tar.gz 2. 解压缩 $ tar xzf redis-3.0.7.tar.gz 3. 编译 $ cd redis-3.0.7 $ make $make install $cp redis.conf /etc/ #该步骤将配置文件放入etc方便管理 特别说明: make