[nosql之redis]yum安装redis

时间:2022-12-07 02:42:17

1.首先对于这种nosql来说目前我用到的功能很少,所以感觉没有必要去优化他跟不需要去编译安装。今天来介绍下一个yum安装redis

步骤1:安装扩展yum库

[root@localhost ~]# yum install epel-release
##在查看下yum源中是否有redis
[root@localhost ~]# yum search redis
[root@localhost ~]# yum -y install redis
##ok安装完成!

启动:

##CentOS7
[root@localhost ~]# systemctl start redis.service
##CentOS7以下
[root@localhost ~]# service redis start
##查看启动:
[root@localhost ~]# ps -ef | grep redis
redis 12683 1 0 23:19 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379
root 12696 12454 0 23:20 pts/2 00:00:00 grep --color=auto redis

客户端连接:

[root@localhost ~]# redis-cli
127.0.0.1:>
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:> set a
OK
127.0.0.1:> get a
""
127.0.0.1:> keys *
) "a"
127.0.0.1:> del a
(integer) 1
127.0.0.1:6379> keys *
(empty list or set)

开机自启动:两种方式

方法1: 启动命令写入 /etc/rc.d/rc.local 文件里面

[root@localhost ~]# echo 'systemctl start redis.service' >> /etc/rc.d/rc.local
[root@localhost ~]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot. touch /var/lock/subsys/local
memcached -u memcached -p -m -c &
systemctl start redis.service

方法2:加入系统服务 :我这里用yum安装本身就是加入了系统服务了只需要设置开机自启动就可以:

[root@localhost ~]# systemctl enable redis.service