Home > Database > Redis > body text

How to deploy redis on linux

PHPz
Release: 2023-05-30 16:08:13
forward
1146 people have browsed it

1. Download the Linux version of redis from the official website

2. Copy to the Linux server and decompress it to the specified directory

3. After decompression, get the redis folder-----Move to The file location you know

4. Note: redis is written in c language and needs to rely on the c language environment

yum install gcc-c++ tcl
Copy after login

Enter the redis installation directory

Execute

make---------------编译redis
注意:redis6以上版本make编译可能报错,需要升级gcc版本
#第一步
sudo yum install centos-release-scl
#第二步
sudo yum install devtoolset-7-gcc*
#第三步
scl enable devtoolset-7 bash
Copy after login

Finally proceed

make install
Copy after login

5.redis default installation pathuse/local/bin

After compilation and installation, it will be in this directory

redis- server server

redis-cli client

6. We can copy the configuration file: redis.conf file in the redis installation directory to: use/local/redisconf/redis.con

Note: redisconf is a folder we created ourselves to place the configuration file. An error causes the program to fail to start (make a backup)

7. After completing the above steps, you can start redis

redis-server /usr/local/rediscong/redis.conf
redis-cli----启动客户端
Copy after login

8Some configuration analysis in the redis.conf file

bind 127.0.0.1 -::1 
指定 redis 只接收来自于该 IP 地址的请求
在配置文件redis.conf中,默认的bind 接口是127.0.0.1,也就是本地回环地址。这样的话,访问redis服务只能通过本机的客户端连接,而无法通过远程连接,
这样可以避免将redis服务暴露于危险的网络环境中,防止一些不安全的人随随便便通过远程
连接到redis服务。
如果bind选项为空的话,那会接受所有来自于可用网络接口的连接。
(绑定的是服务器上网卡的ip,不是谁要连接绑定谁的ip,绑定服务器网卡连接后,远程访问只要通过这个网卡地址来的Redis请求,都可以访问redis)

远程连接可采取指定多个IP方式,例:bind 192.168.11.129 127.0.0.1
或者:bind 0.0.0.0----服务器上所有的ipv4地址
Copy after login
daemonize---此配置有两个值 yes/no 
守护进程(daemon)是一类在后台运行的特殊进程,用于执行特定的系统任务。很多守护进程在系统引导的时候启动,并且一直运行直到系统关闭。另一些只在需要的时候才启动,完成任务后就自动结束
当daemonize yes代表开启守护线程---守护进程开启后台启动
当daemonize no 代表关闭守护线程
Copy after login
protected-mode---此配置有两个值 yes/no 
保护模式
当protected-mode yes代表开启保护模式---(当没有为redis显示指定bind且没有设置密码时,此时redis就认为是不安全的,当开启保护模式后,保护模式的作用是只允许本地回环地址127.0.0.1和::1(ipv6回环地址的表示形式)访问。)
当protected-mode no 代表关闭保护模式
Copy after login
requirepass password ---设置密码
在配置文件中设置密码需要重启redis服务
客户端启动
1:redis-cli---进入命令行
2:auth password---输入密码
在客户端修改redis密码
修改密码:config set requirepass password
查看密码:config get requirepass
Copy after login

Connection failure may occur when using RedisDesktopManager to connect to the redis service

The method to solve this problem is as follows

1. Make sure bind is set in the configuration file

2. You need to set a password when turning on protected mode

3. Modification of the configuration file requires restarting the service

redis startup and shutdown

redis的启动命令
redis-server  /usr/local/rediscong/redis.conf
如在/user/local/rediscong/目录下输入命令redis-server  /usr/local/rediscong/redis.conf ,那么redis备份文件就在/user/local/rediscong/dump.rdb
redis关闭命令
进入客户端redis-cli 
执行shutdown
Copy after login

The above is the detailed content of How to deploy redis on linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!