1、安装gcc依赖

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

>yum install -y gcc tcl #装 gcc 编译器和 redis 测试使用到的 tcl 库

安装6版本的redis,gcc版本一定要5.3以上,centos6.6默认安装4.4.7;centos7.5.1804默认安装4.8.5,这里要升级gcc了。
可以通过命令gcc -v可以查看gcc的版本,检查版本是否过低。升级命令

>yum -y install centos-release-scl && yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils && scl enable devtoolset-9 bash
#注意:scl命令启用只是临时的,退出xshell或者重启就会恢复到原来的gcc版本。
#如果要长期生效的话,执行如下:
>echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

2、下载安装

> wget https://download.redis.io/releases/redis-6.0.10.tar.gz
> tar xzf redis-6.0.10.tar.gz
> cd redis-6.0.10
> make
>make install PREFIX=/usr/local/redis #安装并指定安装目录

2.1 安装成系统服务

>./utils/install_server.sh

2.1.1 报错Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry

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,注释掉下面的内容:

#_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
#unset _pid_1_exe

2.2.2 报错Mmmmm...  it seems like you don't have a redis executable. Did you run make install yet?

按如下修改

2.2.3 执行后,查看启动状态

>systemctl status redis_6379
Unit redis.service could not be found.
[root@iZ2zeck0io750hybqc9ixiZ ~]# systemctl status redis_6379
● redis_6379.service - LSB: start and stop redis_6379
   Loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)

2.2 文件位置

Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli

3、修改配置文件

修改redis.conf 配置文件

  • daemonize修改为yes即可守护进程模式后台启动。
  • 密码默认为空、若要设置密码、可以通过放开注释# requirepass foobared
  • 远程访问需要在将bind 127.0.0.1配置注释,修改protected-mode no,重启即可。

 

 

 

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐