Linux下安装Redis
一、进入到/mnt/ 文件目录中 ,使用whet命令进行下载Redis,解压 redis-4.0.8.tar.gz,把redis-4.0.8移动到/usr/local/
[root@pd-common ~]# cd /mnt/
[root@pd-common mnt]# wget http://download.redis.io/releases/redis-4.0.8.tar.gz //下载
[root@pd-common mnt]# tar -zxvf redis-4.0.8.tar.gz //解压
[root@pd-common mnt]# ls
redis-4.0.8 redis-4.0.8.tar.gz
[root@pd-common mnt]# mv redis-4.0.8 /usr/local //把redis-4.0.8移动到/usr/local/
二、如果出现 -bash: wget 未找到命令
那么 输入命令:yum -y install wget ,安装 wget
三、安装gcc环境
[root@pd-common mnt]# yum install gcc-c++
四、编译安装
[root@pd-common mnt]# cd /usr/local/redis-4.0.8
[root@pd-common redis-4.0.8]# make //对解压后的文件进行编译
[root@pd-common redis-4.0.8]# cd ./src
[root@pd-common src]# make install //安装
五、Redis的部署
首先为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中
1、创建bin和etc文件
[root@pd-common redis-4.0.8]# mkdir bin
[root@pd-common redis-4.0.8]# mkdir etc
2、将redis-4.0.8目录下的 redis.conf 移动到 redis-4.0.8目录下的etc文件夹下
将redis-4.0.8/src目录下的 mkreleasehdr.sh、redis-benchmark、redis-check-aof、redis-cli、redis-server 移动到 /usr/local/redis-4.0.8/bin/ 目录下
[root@pd-common redis-4.0.8]# mv redis.conf ./etc/ //移动redis.conf
[root@pd-common redis-4.0.8]# cd ./src //进redis-4.0.8/src
[root@pd-common src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server /usr/local/redis-4.0.8/bin/ //移动
六、编辑 redis.conf配置文件
[root@pd-common src]# cd /usr/local/redis-4.0.8/etc/ //进入etc
[root@pd-common etc]# vi redis.conf //编辑
配置信息
1、daemonize 如果需要在后台运行,把该项改为yes
把文件中的daemonize属性改为yes(表明需要在后台运行)
2、pidfile 配置多个pid的地址 默认在/var/run/redis.pid
3、bind 绑定ip,设置后只接受来自该ip的请求
把 redis.conf配置文件中的 bind 127.0.0.1
这一行给注释掉,这里的bind指的是只有指定的网段才能远程访问这个redis,注释掉后,就没有这个限制了。
4、port 监听端口,默认是6379
5、loglevel 分为4个等级:debug verbose notice warning
6、logfile 用于配置log文件地址
7、databases 设置数据库个数,默认使用的数据库为0
8、save 设置redis进行数据库镜像的频率。
9、rdbcompression 在进行镜像备份时,是否进行压缩
10、dbfilename 镜像备份文件的文件名
11、Dir 数据库镜像备份的文件放置路径
12、Slaveof 设置数据库为其他数据库的从数据库
13、Masterauth 主数据库连接需要的密码验证
14、Requriepass 设置 登陆时需要使用密码 (默认密码为空)
设置自己的密码
15、Maxclients 限制同时使用的客户数量
16、Maxmemory 设置redis能够使用的最大内存
17、Appendonly 开启append only模式
18、Appendfsync 设置对appendonly.aof文件同步的频率(对数据进行备份的第二种方式)
19、vm-enabled 是否开启虚拟内存支持 (vm开头的参数都是配置虚拟内存的)
20、vm-swap-file 设置虚拟内存的交换文件路径
21、vm-max-memory 设置redis使用的最大物理内存大小
22、vm-page-size 设置虚拟内存的页大小
23、vm-pages 设置交换文件的总的page数量
24、vm-max-threads 设置VM IO同时使用的线程数量
25、Glueoutputbuf 把小的输出缓存存放在一起
26、hash-max-zipmap-entries 设置hash的临界值
27、Activerehashing 重新hash
28、protected-mode 默认是yes 开启protected-mode保护模式,需配置bind ip或者设置访问密码
把它改成no 要在外部访问服务器中的Redis 除了需要设置 protected-mode no ,还需将 redis.conf 文件中的bind:127.0.0.1语句注释
七、设置Redis开机启动
[root@pd-common etc]# vi /etc/rc.d/rc.local
添加如下代码到 /etc/rc.d/rc.local 中:
/usr/local/redis-4.0.8/bin/redis-server /usr/local/redis-4.0.8/etc/redis.conf
八、启动
切换到 /usr/local/redis-4.0.8/bin/ 目录下执行 redis-server 命令,使用 /usr/local/redis-4.0.8/etc/redis.conf配置文件来启动redis服务
[root@pd-common etc]# cd /usr/local/redis-4.0.8/bin/
[root@pd-common bin]# ./redis-server /usr/local/redis-4.0.8/etc/redis.conf //启动
试试用终端redis-cli访问
127.0.0.1:6379> auth 123456 //输入密码
OK
127.0.0.1:6379> set name 123
OK
127.0.0.1:6379> get name
"123"
远程访问Redis
ps:连不上就关防火墙(systemctl stop firewalld.service)
原文链接:https://blog.csdn.net/qq_39135287/article/details/83474865