Linux环境 redis-4.0.8 安装教程

1.获取redis资源

wget http://download.redis.io/releases/redis-4.0.8.tar.gz
2.解压

tar xzvf redis-4.0.8.tar.gz
3.安装

cd redis-4.0.8

make

cd src

make install PREFIX=/usr/local/redis
如果 make 编译失败,可执行以下命令安装 编译所需的环境

yum -y install gcc
yum -y install gcc-c++
再次执行 make 编译命令,如果报 error: jemalloc/jemalloc.h: No such file or directory等这种错误

zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error “Newer version of jemalloc required”
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data0/src/redis-2.6.2/src’
make: *** [all] Error 2
可查看 “Redis 安装报错 error: jemalloc/jemalloc.h: No such file or directory解决方法” 解决问题

4.移动配置文件到安装目录下

cd …/

mkdir /usr/local/redis/etc

mv redis.conf /usr/local/redis/etc
5.配置redis为后台启动

vi /usr/local/redis/etc/redis.conf //将daemonize no 改成daemonize yes
6.将redis加入到开机启动

vi /etc/rc.local //在里面添加内容:/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (意思就是开机调用这段开启redis的命令)
7.开启redis

/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
常用命令

redis-server /usr/local/redis/etc/redis.conf //启动redis

pkill redis //停止redis

卸载redis:

rm -rf /usr/local/redis //删除安装目录

rm -rf /usr/bin/redis-* //删除所有redis相关命令脚本

rm -rf /root/download/redis-4.0.4 //删除redis解压文件夹
扩展:
1、给redis设置登录密码

需要永久配置密码的话就去redis.conf的配置文件中找到requirepass这个参数,如下配置:

将 # requirepass foobared 注释打开
并修改为 requirepass xxx #指定密码xxx
保存后重启redis就可以了

2、远程连接失败问题:

同样修改redis.conf配置文件

#bind 127.0.0.1 修改为 bind 0.0.0.0
redis密码方式登录

./redis-cli -h 127.0.0.1 -p 6379 -a yourpassword

1.Redis服务端正在加载数据时,由于退出redis服务端或者关闭redis服务端窗口…,导致无法再次进入redis服务端,如下错误:

$ redis-server # 启动redis服务端
1051:C 06 May 2019 14:13:49.227 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1051:C 06 May 2019 14:13:49.227 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=1051, just started
1051:C 06 May 2019 14:13:49.227 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1051:M 06 May 2019 14:13:49.228 * Increased maximum number of open files to 10032 (it was originally set to 256).
1051:M 06 May 2019 14:13:49.228 # Could not create server TCP listening socket *:6379: bind: Address already in use
(1)解决错误信息:

查看系统限制

$ ulimit -a

设置“open files”数量

$ ulimit -n 10032

2.再次进入redis服务端,如下错误:

$ redis-server
1061:C 06 May 2019 14:14:36.611 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1061:C 06 May 2019 14:14:36.611 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=1061, just started
1061:C 06 May 2019 14:14:36.611 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1061:M 06 May 2019 14:14:36.613 # Could not create server TCP listening socket *:6379: bind: Address already in use
6379地址已经在使用(6379是redis默认的端口)
(2)解决错误信息:

$ ps -ef | grep -i redis

进程号3272是redis的服务器

2.2、杀死该进程

使用"kill -9"命令
kill -9 3272  # 进程3272是redis服务器
2.3、重新启动redis服务器

$ redis-server
5377:C 05 May 2019 21:20:46.788 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5377:C 05 May 2019 21:20:46.788 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=5377, just started
5377:C 05 May 2019 21:20:46.788 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
.
.-__ ''-._ _.- .. ‘’-._ Redis 5.0.4 (00000000/0) 64 bit
.-.-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.-.|’_.-'| Port: 6379 |-. ._ / _.-' | PID: 5377-._ -._-./ .-’ .-’
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' | http://redis.io-._ -._-..-’.-’ .-’
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' |-._ -._-.
.-’_.-’ _.-’
-._-..-’ _.-’
-._ _.-'-.
.-’

5377:M 05 May 2019 21:20:46.791 # Server initialized
5377:M 05 May 2019 21:20:46.791 * Ready to accept connections

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章