您现在的位置是:网站首页> 后端技术 正文 CentOS7系统Redis安装教程 眰恦 2022/05/31 23:12:16 538 0 5 简介:Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。 # Redis安装 ### 1、创建文件夹并进入目录 ```shell [root@localhost local]# mkdir redis [root@localhost local]# cd redis ``` ### 2、下载压缩包 ```shell [root@localhost redis]# wget http://download.redis.io/releases/redis-6.2.6.tar.gz ``` ### 3、开始安装 ①解压 ```shell [root@localhost redis]# tar -zxvf redis-6.2.6.tar.gz ``` ②进入Redis目录 ```shell [root@localhost redis]# cd redis-6.2.6/ ``` ③编译(等待编译完成) ```shell [root@localhost redis-6.2.6]# make ``` ④安装 ```shell [root@localhost redis-6.2.6]# make install ``` ### 4、启动Redis服务端 ①创建存放修改后配置文件的目录 ```shell [root@localhost redis-6.2.6]# mkdir myconfig ``` ②复制原配置文件到修改后的存放目录 ```shell [root@localhost redis-6.2.6]# cp redis.conf myconfig/ ``` ③进入创建的目录 ```shell [root@localhost redis-6.2.6]# cd myconfig/ ``` ④编辑redis.conf ```shell [root@localhost myconfig]# vim redis.conf ``` ⑤配置redis.conf中daemonize为yes,确保守护进程开启。 ```shell daemonize yes ``` ⑥进入Redis的src下启动Redis服务端 ```shell [root@localhost src]# ./redis-server ../myconfig/redis.conf ``` ⑦查看Redis进程 ```shell [root@localhost src]# ps -ef | grep redis root 22664 1 0 23:55 ? 00:00:00 ./redis-server 127.0.0.1:6379 root 23279 4584 0 23:57 pts/0 00:00:00 grep --color=auto redis ``` ### 5、设置Linux开机自启动Redis服务 ①输入命令 ```shell [root@localhost src]# vi /lib/systemd/system/redis.service ``` ```shell [Unit] Description=The redis-server Process Manager Documentation=https://redis.io/ After=network.target [Service] Type=forking #路径指向Redis安装目录下的src启动 修改后配置文件的目录redis.conf ExecStart=/usr/local/redis/redis-6.2.6/src/redis-server /usr/local/redis/redis-6.2.6/myconfig/redis.conf #有密码则需要在cli后面加 -a "密码" ExecStop=/usr/local/redis/redis-6.2.6/src/redis-cli shutdown [Install] WantedBy=multi-user.target ``` ②设置开机自启动 ```shell [root@localhost myconfig]# systemctl enable redis ``` ### 6、启动客户端测试 ```shell [root@localhost src]# redis-cli 启动客户端(默认配置可以使用这个命令,如果命令没有设置为全局变量,就要加./) localhost:6379> ping PONG 测试客户端,输出PONG表示成功 服务端绑定地址 端口 [root@localhost src]# ./redis-cli -h localhost -p 6379 localhost:6379> exit / ctrl+c 退出客户端 ``` ### 7、常用命令 ```shell #开启服务 [root@localhost src]# systemctl start redis #停止服务 [root@localhost src]# systemctl stop redis #查看运行状态 [root@localhost src]# ps -ef | grep redis ``` 很赞哦! (5) 上一篇:CentOS7系统MySql安装教程 下一篇:排序算法--java 文章评论 选择头像: 您的姓名: 您的邮箱: 评论内容: 提交 评论 目录