linux安装redis
从官文下载最新版的redis.tar.gz(https://redis.io/download)
复制到Centos中的一个文件夹(如/usr/local/)
解压redis到该文件夹中 tar -zxvf redis-7.0.5.tar.gz
进入解压目录中 cd redis-7.0.5
可能需要安装gcc:安装redis需要环境下已经安装最新版的GCC(因为redis是最新版的,要是redis版本低于5的可不用安装最新版的GCC )。安装操作参考文章https://blog.csdn.net/qq_43751336/article/details/114299796
在redis目录下输入make
切换到redis的src目录
cd src
然后输入
make install PREFIX=/usr/local/redis/redis-7.0.5
(此处为自己的路径)
修改redis.conf文件,让其可以远程连接
vi redis.conf
vi /usr/local/redis/redis-7.0.5/redis.conf
requirepass password
daemonize yes
port 6859
bind 127.0.0.1 #若不成功,直接开放到最大的地址 0.0.0.0
protected-mode yes
安装完成,启动/opt/redis/redis-6.2.3/bin/redis-server
再起启动生效
==============
常用命令
get WB:100884716210001101488304010001
keys get WB:100884716210001101488820010001
cd /opt/redis/redis-6.2.3/bin
客户端登录
./redis-cli -h 127.0.0.1 -p 6389 -a password
./redis-cli -h 127.0.0.1 -p 6389 -a password
关闭
redis-cli -h 127.0.0.1 -p 6859-a password
进入之后,输入命令:
shutdown
启动
用systemd启动
# 验证状态
netstat -lntp | grep
6389
ps aux | grep redis
netstat -lntp
防火墙
firewall-cmd --permanent --remove-port=6389/tcp
firewall-cmd --permanent --add-port=6389/tcp
CONFIG GET bind
CONFIG Set bind value
CONFIG GET protected-mode
配置
requirepass password
daemonize yes
port 6389
配置开机启动
https://blog.csdn.net/sebeefe/article/details/124167427
vim /etc/systemd/system/redis-server.service
[Unit] Description=Redis Server After=network.target [Install] WantedBy=multi-user.target [Service] Type=forking PIDFile=/var/run/redis_6379.pid ExecStart=/usr/local/redis/redis-7.0.4/bin/redis-server /usr/local/redis/redis-7.0.4/redis.conf ExecStop=/usr/local/redis/redis-7.0.4/bin/redis-cli -p 6389 -a wfb147852 shutdown ExecReload=/bin/kill -s HUP $MAINPID PrivateTmp=true
systemctl daemon-reload
systemctl start redis-server.service
systemctl status redis-server.service
systemctl enable redis-server.service
systemctl is-enabled redis-server.service
ln -s /usr/local/redis/redis-7.0.5/bin/redis-cli /usr/bin/redis-cli+ ln -sf /usr/local/redis/redis-7.0.5/bin/redis-cli /usr/bin/redis-cli