Redis安装详细步骤

一、redis软件下载

下载地址:

1.https://redis.io/(英文网站)

2.http://redis.cn/(中文网站)

二、安装

1.在redis下载网站,复制下载地址,然后再linux中通过wget下载

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

2.解压

tar -xf redis-6.0.10.tar.gz

3.安装

解压完成后,通过make命令安装,但是我在执行完make命令之后报错了,因为用的是腾讯云服务器,这种情况一般是gcc版本低了:

make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/root/redis-6.0.1/src'
make: *** [install] Error 2

出现这个问题需要先确认GCC的版本,命令如下:

gcc -v

发现CentOS7默认的gcc版本为4.8.5,安装Redis6.0需要将gcc版本升级到5.3以上,则升级gcc命令如下:

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
 
#临时修改gcc版本
scl enable devtoolset-9 bash
#永久修改gcc版本
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

执行完成后,再次查看gcc的版本

[root@VM-0-6-centos home]# 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-44) (GCC) 
[root@VM-0-6-centos home]#

升级完了gcc版本后,再重新make,这次就不会报错了,执行完成后会提示安装成功

4.配置环境变量

执行安装路径

make install PREFIX=/usr/local/redis

配置环境变量

 vi /etc/profile
export REDIS_HOME=/usr/local/redis
exprot PATH=$PATH:${REDIS_HOME}/bin

然后source一下

source /etc/profile

再执行utis目录下的 install_server.sh 

 ./install_server.sh 

此时会提示错误信息:

[root@VM-0-6-centos utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

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文件

vi ./install_server.sh

注释掉下面这段代码,然后重新执行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

重新执行 ./install_server.sh

 ./install_server.sh

会有如下的提示信息,直接默认就好了

Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/redis/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/redis/bin/redis-server
Cli Executable : /usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@VM-0-6-centos utils]# 

此时,已经默认帮我们启动了redis了,查看下redis的状态,可以看到redis真的已经启动了

[root@VM-0-6-centos local]# cd /etc/init.d/
[root@VM-0-6-centos init.d]# ll
total 120
-rw-r--r-- 1 root root 18281 Aug 19  2019 functions
-rwxr-xr-x 1 root root 10576 Oct 10 10:55 mysqld
-rwxr-xr-x 1 root root  4569 Aug 19  2019 netconsole
-rwxr-xr-x 1 root root  7928 Aug 19  2019 network
-rwxr-xr-x 1 root root 63534 Aug  5  2020 openibd
-rw-r--r-- 1 root root  1160 Aug  7 01:30 README
-rwxr-xr-x 1 root root  1714 Feb  5 11:57 redis_6379
[root@VM-0-6-centos init.d]# service redis_6379 satus
Please use start, stop, restart or status as first argument
[root@VM-0-6-centos init.d]# service redis_6379 status
Redis is running (7975)
[root@VM-0-6-centos init.d]# 

到此,reids已经安装完成了。

小编也有自己微信公众号:“JAVA菜鸟程序猿”,喜欢的可以关注下哦!

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JAVA菜鸟程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值