Redis在Centos7下的安装和配置

1.下载

官方网站地址:https://redis.io/ ,下载最新版本

# wget http://download.redis.io/releases/redis-4.0.1.tar.gz
2. 解压安装
# tar zxf redis-4.0.1.tar.gz 
# cd redis-4.0.1/
# make
# make install

安装服务(默认即可)

# ./utils/install_server.sh 

查看启动状态

# ps -ef|grep redis
3. 配置
# vi /etc/redis/6379.conf 

编辑修改如下1、去掉bind 127.0.0.1 2、配置访问密码


启动

# redis-server /etc/redis/6379.conf 

添加访问tcp端口

# firewall-cmd --zone=public --add-port=6379/tcp --permanent
# firewall-cmd --reload
4. 测试
# redis-cli

命令行
Redis-server /usr..../redis.conf 启动redis服务,并指定配置文件
Redis-cli 启动redis 客户端
Pkill redis-server 关闭redis服务
Redis-cli shutdown 关闭redis客户端
Netstat -tunpl|grep 6379 查看redis 默认端口号6379占用情况

5.常用命令
auth 123 #输入密码进入
set  a 123 #设置key为a 值为123
get a #获取key值为a的value
keys aa* #模糊查询key值以aa为开头的
redis-cli -a 'password' KEYS "aa_*" | xargs redis-cli -a 'passwor' DEL #删除以aa_为开头的
6.V6.0.9安装问题

需要先更新gcc版本

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils 
scl enable devtoolset-9 bash
#scl命令启用只是临时的,退出xshell或者重启就会恢复到原来的gcc版本。
#如果要长期生效的话,执行如下
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

安装Redis 6.0.9 ./install_server.sh报错

This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!

需要编辑install_server.sh,注释掉以下代码即可

#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#       echo "This systems seems to use systemd."
#       echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
#       exit 1
#fi
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容