经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Linux/Shell » 查看文章
CentOS7.6下安装Redis5.0.7
来源:cnblogs  作者:JubilantZ  时间:2022/1/3 20:17:24  对本文有异议

此次安装是在CentOS7下安装Redis5.0.7

一.首先准备Redis安装包

  1. 这里下载的是 redis-5.0.7.tar.gz 安装包,并将其直接放在了 root ?录下
  2. 压缩包下载地址:https://files.cnblogs.com/files/blogs/726807/redis-5.0.7.tar.gz

二.解压安装包

2.1在/data下创建redis文件夹并进入

  1. cd /data/
  2. mkdir redis
  3. cd redis

2.2将安装包解压到/data/redis/

  1. tar zxvf /root/redis-5.0.7.tar.gz -C /data/redis

解压完之后会在/data/redis/下生成一个redis-5.0.7的文件夹

三.编译并安装

  1. cd /data/redis/redis-5.0.7
  2. make && make PREFIX=/data/redis install

注意:因为缺少相关的包导致编译失败

举例:
1.缺少gcc,则安装gcc

yum -y install gcc

2.make时报如下错误:
  1. zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
  2. zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
  3. make[1]: *** [adlist.o] Error 1
  4. make[1]: Leaving directory `/data0/src/redis-2.6.2/src'
  5. make: *** [all] Error 2

原因是jemalloc重载了Linux下的ANSIC的malloc和free函数。解决办法:make时添加参数。

  1. make MALLOC=libc
3.make之后,会出现一句提示Hint: To run 'make test' is a good idea ;

但是不测试,通常是可以使用的。若我们运行make test ,会有如下提示

  1. [devnote@devnote src]$ make test
  2. You need tcl 8.5 or newer in order to run the Redis test
  3. make: ***[test] Error_1

解决办法是用yum安装tcl8.5(或去tcl的官方网站http://www.tcl.tk/下载8.5版本,并参考官网介绍进行安装)

  1. yum -y install tcl

补:问题解决完了最好再重新编译下。

四.将Redis安装为系统服务并后台启动

  1. [root@localhost redis-5.0.7]# cd utils/
  2. //运行服务脚本 脚本中redis安装路径为/data/redis
  3. //此处我全部选择的默认配置即可,有需要可以按需定制!!!
  4. //参考地址:https://files.cnblogs.com/files/blogs/726807/install_server.sh
  5. //可以直接粘贴上我的我把所有用到的Redis的所有配置都放在了/data/redis目录下
  6. 说明:为了方便,最好自己配置一下install_server.sh中的路径,就比如后续启动需要的redis-server 配置文件6379.conf 把它俩放到建的redis文件夹下,方便查找
  7. [root@localhost utils]# ./install_server.sh

五.查看Redis服务启动情况,并停止Redis服务

  1. //查看服务状态
  2. systemctl status redis
  3. //停止服务
  4. systemctl stop redis
  5. //结束进程
  6. ps -ef|grep redis
  7. kill -9 PID

六.修改配置文件和修改系统配置(保证redis的远程可以访问)

6.1.编辑redis配置文件

  1. vi /etc/redis/6379.conf(默认配置文件位置,修改自己实际配置文件)

? vi /data/redis/16379.conf

  1. 修改内容:
  2. 1. bind 127.0.0.1 修改为 0.0.0.0 //修改IP
  3. 2.daemonize yes //在后台运行
  4. 3.protected-mode 设置成no(默认是设置成yes的, 防止了远程访问,在redis3.2.3版本后)
  5. 4.requirepass 123456 //设置密码 可不设置

6.2.关闭防火墙和SELINUX

6.2.1关闭防火墙

  1. 1、停止firewalld服务
  2. systemctl stop firewalld
  3. 2、禁止firewalld开机启动
  4. systemctl disable firewalld

6.2.2关闭SELINUX

  1. vi /etc/selinux/config
  2. `SELINUX=enforcing`修改为`SELINUX=disabled`,保存退出

七.启动Redis并远程访问

7.1启动Redis (使用绝对路径启动,一劳永逸,免去一些找不到命令错误)

  1. /usr/local/bin/redis-server /etc/redis/6379.conf //此处使用的是默认路径
  2. /data/redis/bin/redis-server /data/redis/16379.conf //自己的路径

? ps -ef|grep redis //查看是否启动成功

7.2远程访问Redis

? 输入IP,默认端口号6379,密码,测试连接,搞定!

八.设置开机启动Redis(建议设置)

  1. 方式 1 vi /etc/rc.d/rc.local
  2. 添加启动命令到 /etc/rc.d/rc.local 中:
  3. /usr/local/redis-5.0.7/bin/redis-server /etc/redis/redis.conf //此处使用的是默认路径
  4. /usr/local/redis/bin/redis-server /usr/local/redis/6379.conf //自己的路径

? 方式 2 . vi /lib/systemd/system/redis.service

  1. [Unit]
  2. Description=Redis
  3. After=syslog.target network.target remote-fs.target nss-lookup.target
  4. [Service]
  5. Type=forking
  6. #PIDFile=/data/redis/redis.pid
  7. ExecStart=/data/redis/bin/redis-server /data/redis/16379.conf
  8. ExecReload=/bin/kill -s HUP $MAINPID
  9. ExecStop=/bin/kill -s QUIT $MAINPID
  10. ExecStartPost=/bin/sh -c "echo $MAINPID > /data/redis/redis.pid"
  11. PrivateTmp=true
  12. [Install]
  13. WantedBy=multi-user.target
  1. //重载系统服务
  2. sudo systemctl daemon-reload

原文链接:http://www.cnblogs.com/jubilantz/p/15755409.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号