Centos7安装Redis的方法

这篇文章给大家分享的是有关Centos 7安装redis的方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

黄浦网站建设公司创新互联建站,黄浦网站设计制作,有大型网站制作公司丰富经验。已为黄浦上千提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的黄浦做网站的公司定做!

一、安装gcc依赖

redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装。

$ yum install -y gcc

二、下载并解压安装包

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

$ tar -zxvf redis-5.0.7.tar.gz

三、cd切换到redis解压目录下,执行编译

$ cd redis-5.0.7 && make

四、安装并指定安装目录

$ make install PREFIX=/usr/local/redis

五、启动服务

5.1 前台启动

$ cd /usr/local/redis/bin/

$ ./redis-server

5.2后台启动

从 redis 的源码目录中复制 redis.conf 到 redis 的安装目录

$ cp /usr/local/redis-5.0.7/redis.conf /usr/local/redis/bin/

修改 redis.conf 文件,把 daemonize no 改为 daemonize yes

$ vim redis.conf

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

后台启动

$ ./redis-server redis.conf

六、设置开机启动

添加开机启动服务

$ vim /etc/systemd/system/redis.service

添加下面内容

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

注意:ExecStart 配置成自己的路径

设置开机启动

$ systemctl daemon-reload

$ systemctl start redis.service

$ systemctl enable redis.service

创建 redis 命令软链接

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

# 测试
$ redis

127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

最后,贴一下常用命令~

# 启动redis服务
systemctl start redis.service

# 停止redis服务
systemctl stop redis.service

# 重新启动服务
systemctl restart redis.service

# 查看服务当前状态
systemctl status redis.service

# 设置开机自启动
systemctl enable redis.service

# 停止开机自启动
systemctl disable redis.service

OK~完事~

感谢各位的阅读!关于“Centos 7安装Redis的方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


分享题目:Centos7安装Redis的方法
网页网址:http://myzitong.com/article/ppoehd.html