CentOS7安装redis

一、安装Redis


step1.安装gcc依赖

由于redis是用c语言开发,安装之前必须先确认是否安装了gcc环境。

[root@localhost bin]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)

安装gcc,yum install -y gcc

step2. 下载redis,并解压

[root@localhost local]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz
[root@localhost local]# tar -zxvf redis-5.0.3.tar.gz

step3. 切换到redis解压目录下,执行编译

[root@localhost local]# cd redis-5.0.3
[root@localhost local]# make

step4. 安装并制定安装目录

[root@localhost local]# make install PREFIX=/usr/local/redis

注:如果目录不存在,需先创建目录。



二、启动服务


前台启动

[root@localhost local]# cd /usr/local/redis/bin
[root@localhost local]#  ./redis-server

后台启动

step1

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

[root@localhost redis-5.0.5]# cp /home/jack/Templates/redis-5.0.5/redis.conf /usr/local/redis/bin/
step2

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

[root@localhost local]# vim redis.conf
[root@localhost local]# ./redis-server redis.conf
[root@localhost bin]# vim redis.conf
[root@localhost bin]# ./redis-server redis.conf
88798:C 28 Jun 2020 21:28:45.774 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
88798:C 28 Jun 2020 21:28:45.774 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=88798, just started
88798:C 28 Jun 2020 21:28:45.774 # Configuration loaded


三、设置开机启动


step1. 添加开机启动服务

[root@localhost local]# vi /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配置成自己的 redis 安装路径:redis-server 和 redis.conf

step2. 设置开机启动

[root@localhost local]# systemctl daemon-reload
[root@localhost local]# systemctl start redis.service
[root@localhost local]# systemctl enable redis.service
创建 redis 命令软连接
[root@localhost local]# In -s /usr/local/redis/bin/redis-cli /usr/bin/redis
测试redis
[root@localhost src]# ./redis-cli
127.0.0.1:6379> keys *
(empty list or set)
服务操作命令

systemctl start redis.service #启动redis服务

systemctl stop redis.service #停止redis服务

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

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

[root@localhost src]# systemctl status redis.service
● redis.service - redis-server
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

Jun 28 21:36:29 localhost.localdomain systemd[1]: Starting redis-server...
Jun 28 21:36:29 localhost.localdomain redis-server[91744]: 91744:C 28 Jun 2020 21:36:29.922 # oO0OoO0O...Oo
Jun 28 21:36:29 localhost.localdomain redis-server[91744]: 91744:C 28 Jun 2020 21:36:29.922 # Redis ve...ed
Jun 28 21:36:29 localhost.localdomain redis-server[91744]: 91744:C 28 Jun 2020 21:36:29.922 # Configur...ed
Jun 28 21:36:29 localhost.localdomain systemd[1]: Started redis-server.
Hint: Some lines were ellipsized, use -l to show in full.

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值