一。Linux 安装并运行Redis

一. 安装

    进入官网,downLoad 右键复制链接地址,得到类似 的地址; 登录要安装的机器,yum install wget ,安装wget 工具; 命令wget ; 安装到当前目录中; 解压压缩包 tar xf redis-6.0.10.tar.gz; 得到文件夹 redis-6.0.10;

二.编译

    执行make 一般第一次干净的linux 会缺少gcc ,安装gcc;yum install gcc; 如果执行make会报错形如

则需要升级gcc ,然后再执行make;

    升级gcc
1:yum -y install centos-release-scl

2:yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

3:scl enable devtoolset-9 bash
    执行完make,会在src 文件夹中生成一些可执行的文件,类似redis-server;在当前文件夹中执行./redis-server 即可执行程序;

ctrl+c 结束以上

三.构建

    除了上边直接手动进行运行,可以将其装载成服务; make PREFIX=/opt/redis install 将redis 安装到根目录下/opt/redis 目录下;目的是将可执行程序服务与源码分离,便于管理; 回到 redis-6.0.10 ,进入utils目录 cd utils/ ,执行install_server.sh ;在此之前,这个脚本需要知道程序安装到了哪里,这里就需要配置环境变量; 执行命令 vi /etc/profile ;到文件最后增加 两行 export REDIS_HOME=/opt/redis ;export PATH=$PATH:$REDIS_HOME/bin 执行命令 source /etc/profile;使上边命令生效;echo $PATH 查看配置 ;之后redis_cli 就可以在任何位置来运用了 运行./install_server.sh的时候出现这个问题 后来一搜下面那样解决就好了

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 把下面这一段进行注释

#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,一直回车键,会有如下结果;这个是安装实例的命令,多次执行的时候,选择不同的端口即可以区分不同的实例;
[root@VM-0-4-centos utils]# ./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 [/opt/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     : /opt/redis/bin/redis-server
Cli Executable : /opt/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
    当有多个实例同时运行的时候,ps -fe | grep redis 命令就可以查看不同的实例情况了
    此时在任何地方执行 service redis_6379 start, stop, restart or status 就可以启动,停止 或者看运行状态了;6379 是上边选的端口号,一般这个是默认,当机器安装多个实例的时候,只需要根据端口号进行区分就可以了; redis-cli 回车即可启动默认实例,进行命令行的操作了;
经验分享 程序员 微信小程序 职场和发展