Centos7 install Redis and set up remote access

                        Centos7 install Redis and set up remote access

1. Download the installation file

Go to the Redis website to download the latest stable version of the Redis installation package

wget http://download.redis.io/releases/redis-stable.tar.gz

  

Two, unzip the installation file

tar -xzvf redis-stable.tar.gz

Three, start the installation

Go to the unzip directory

cd redis-stable/

  

Enter the decompressed file directory, and then directly compile it (if an error occurs, follow: https://blog.csdn.net/happyzwh/article/details/106373688 )

make

  

Create a directory for storing redis files and copy redis-server redis-cli to the newly created folder

mkdir -p /usr/local/redis
cp /home/software/redis-stable/src/redis-server /usr/local/redis/
cp /home/software/redis-stable/src/redis-cli /usr/local/redis/

Set Redis to start automatically when booting

Enter the redis-stable/utils directory and execute ./install_server.sh

   
View Redis process

ps -ef|grep redis

  
 Redis Open Remote Access
 Open the Redis configuration set in the above steps, the default is: /etc/redis/6379.conf, modify the configuration file as follows, and the others remain unchanged

daemonize yes
#bind 127.0.0.1 (不限制IP)
protected-mode no
#将 requirepass foobared前的“#”去掉,密码改为你想要设置的密码(如123456)

 Modify the redis service script and add the following information:

vim /etc/init.d/redis_6379
# 修改 添加 -a "password"
$CLIEXEC -a "123456" -p $REDISPORT shutdown

   

Restart service

service redis_6379 restart
 
# 开放6379端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
# 重启防火墙,否则开放端口不起作用
firewall-cmd --reload

  

Create a redis command soft connection, so that you can enter the redis console

ln -s /usr/local/redis/redis-cli /usr/bin/redis

Close redis service

service redis_6379 stop

Four, Redis configuration


Here are some common configuration items in Redis:

daemonize 如果需要将Redis服务以守护进程在后台运行,则把该项的值改为yes

pidfile 配置多个pid的地址,默认在/var/run/redis/pid

bind 绑定ip,设置后只接受来自该ip的请求

port 监听端口,默认是6379

timeout 客户端连接超时的设定,单位是秒

loglevel 分为4级,debug、verbose、notice、warning

logfile 配置log文件地址

databases 设置数据库的个数,默认使用的数据库为0

save 设置redis进行数据库镜像的频率

rdbcompression 在进行镜像备份时,是否进行压缩

Dbfilename 镜像备份文件的文件名

Dir 数据库镜像备份文件的存放路径

Slaveof 设置数据库为其他数据库的从数据库

Masterauth 主数据库连接需要的密码验证
Requirepass 设置登录时,需要使用的密码
Maxclients 设置同时连接的最大客户端数量
Maxmemory 设置redis能够使用的最大内存
Appendonly 开启append only模式
Appendfsync 设置对appendonly.aof文件同步的频率
vm-enabled 是否开启虚拟内存支持
vm-swap-file 设置虚拟内存的交换文件路径
vm-max-memory 设置redis能够使用的最大虚拟内存
vm-page-size 设置虚拟内存的页大小
vm-pages 设置交换文件的总的page数量
vm-max-threads 设置VMIO同时使用的线程数量
Glueoutputbuf 把小的输出缓存存放在一起
hash-max-zipmap-entries 设置hash的临界值
Activerehashing 重新hash

Modify the configuration parameters of redis: redis.conf
change daemonize no to daemonize yes, save and exit.
ps aux | grep redis Check whether redis is started successfully

netstat -tlun Check whether port 6379 of the host is in use (listening)

./redis-cli Open the redis client

quit Exit the redis client

pkill redis-server close the redis server

./redis-cli shutdown You can also use this command to shut down the redis server

 

redis-cli.exe -h xxx.xxx.xxx.xxx -p 6379 -a 123123 shutdown

Uninstall Redis


1. First check whether redis-server is started

ps ef | grep redis

2. Close these processes
. 3. Delete the corresponding folder of redis. 

Guess you like

Origin blog.csdn.net/u014553029/article/details/101174652