linux安装redis完整步骤

2024-10-09 08:32:41 浏览数 (1)

linux安装redis完整步骤

安装: 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

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解压文件夹

让外网能够访问redis     a.配置防火墙: firewall-cmd --zone=public --add-port=6379/tcp --permanent(开放6379端口)           systemctl restart firewalld(重启防火墙以使配置即时生效)      查看系统所有开放的端口:firewall-cmd --zone=public --list-ports

    b.此时 虽然防火墙开放了6379端口,但是外网还是无法访问的,因为redis监听的是127.0.0.1:6379,并不监听外网的请求。       (一)把文件夹目录里的redis.conf配置文件里的bind 127.0.0.1前面加#注释掉       (二)命令:redis-cli连接到redis后,通过 config get daemonize和config get protected-mode 是不是都为no,如果不是,就用config set 配置名 属性 改为no。

redis.conf文件 # bind 127.0.0.1 daemonize no protected-mode no # redis在最终目标上移动临时数据库文件时出错 将dir ./ 修改为redis配置文件所在目录:/usr/local/redis/etc/  # redis的持久化机制RDB先将内存中的数据集写入临时文件(temp-pid.rdb),写成功后再替换之前的文件(dump.rdb),而现在写入临时文件出错,数据保存不了,导致程序崩溃 dir /usr/local/redis/etc/

# RDB和AOF持久化 #redis有两种持久化方式:一种是RDB持久化(原理是将Reids在内存中的数据库记录定时dump到磁盘上的RDB持久化) #            一种是AOF持久化(原理是将Reids的操作日志以追加的方式写入文件) #RDB是默认开启的,AOF需要修改配置文件来开启 appendonly yes appendfilename "appendonly.aof"

12493:M 27 Dec 19:42:23.095 * 10 changes in 300 seconds. Saving... 12493:M 27 Dec 19:42:23.095 * Background saving started by pid 7905 7905:C 27 Dec 19:42:23.106 # Error moving temp DB file temp-7905.rdb on the final destination crontab (in server root dir /etc): Operation not permitted 12493:M 27 Dec 19:42:23.196 # Background saving error

Redis持久化失败报错 错误: 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. [7679] 15 Jan 00:27:35.287 * DB loaded from disk: 19.629 seconds

解决方案:在Linux系统设置一个参数(vm.overcommit_memory)即可解决。   编辑 sysctl.conf 配置文件:vim /etc/sysctl.conf     vm.overcommit_memory = 1   使配置文件生效:sysctl -p   最后重启redis

配置之后的控制台日志打印如下: [root@hz-auto-test-test5-02 etc]$/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 18679:C 27 Dec 19:52:06.898 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 18679:C 27 Dec 19:52:06.898 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=18679, just started 18679:C 27 Dec 19:52:06.898 # Configuration loaded _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 4.0.8 (00000000/0) 64 bit .-`` .-```. ```/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 18679 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'

18679:M 27 Dec 19:52:06.900 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 18679:M 27 Dec 19:52:06.900 # Server initialized 18679:M 27 Dec 19:52:06.900 # 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. 18679:M 27 Dec 19:52:06.900 * Ready to accept connections 18679:M 27 Dec 19:57:07.096 * 10 changes in 300 seconds. Saving... 18679:M 27 Dec 19:57:07.096 * Background saving started by pid 6584 6584:C 27 Dec 19:57:07.111 * DB saved on disk 6584:C 27 Dec 19:57:07.112 * RDB: 0 MB of memory used by copy-on-write 18679:M 27 Dec 19:57:07.196 * Background saving terminated with success 18679:M 27 Dec 20:01:20.187 * 10000 changes in 60 seconds. Saving... 18679:M 27 Dec 20:01:20.187 * Background saving started by pid 24886 24886:C 27 Dec 20:01:20.224 * DB saved on disk 24886:C 27 Dec 20:01:20.225 * RDB: 0 MB of memory used by copy-on-write 18679:M 27 Dec 20:01:20.287 * Background saving terminated with success

0 人点赞