Centos7 安装 Redis6

Centos7 安装 Redis6 (单机单实例/多实例)

1.准备Centos7 机器

一台Centos7 机器 最好可以上网,安装wget(上网下载工具)

yum install wget 

2.下载包

直接用wget 下载 如果没有联网 也可以下载好传到机器上;

Redis下载地址是 https://download.redis.io/releases/redis-6.2.6.tar.gz

3.解压

[root@localhost soft]# ls
redis-6.2.6.tar.gz
[root@localhost soft]# tar -xvf redis-6.2.6.tar.gz 

4.编译

阅读README.md 大致查看编译步骤;

[root@localhost redis-6.2.6]# make
cd src && make all
    CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 错误 127
make[1]: 离开目录“/soft/redis-6.2.6/src”

报错,没有c 编译环境 安装 GCC

yum install gcc

安装后最好在清除一下 之前安转失败的文件

make distclean

继续安装

make 

构建成功后 src 下回生成执行脚本

Centos7 安装 Redis6_第1张图片

5.执行

7021:C 12 Mar 2022 14:45:45.350 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7021:C 12 Mar 2022 14:45:45.350 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=7021, just started
7021:C 12 Mar 2022 14:45:45.350 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
7021:M 12 Mar 2022 14:45:45.353 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7021:M 12 Mar 2022 14:45:45.353 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7021
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

7021:M 12 Mar 2022 14:45:45.354 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7021:M 12 Mar 2022 14:45:45.354 # Server initialized
7021:M 12 Mar 2022 14:45:45.354 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1'
 for this to take effect.7021:M 12 Mar 2022 14:45:45.354 * Ready to accept connections
^C7021:signal-handler (1647067557) Received SIGINT scheduling shutdown...
7021:M 12 Mar 2022 14:45:57.538 # User requested shutdown...
7021:M 12 Mar 2022 14:45:57.538 * Saving the final RDB snapshot before exiting.
7021:M 12 Mar 2022 14:45:57.539 * DB saved on disk
7021:M 12 Mar 2022 14:45:57.539 # Redis is now ready to exit, bye bye...

成功执行

6.开启自启动

上面的执行方式不是很友好,要想把软件按照到服务里面去,看README.md 可以了解如何去做

[root@localhost redis-6.2.6]# make install  PREFIX=/soft/installdir
//会把对应的命令迁移到这个目录

[root@localhost bin]# pwd
/soft/installdir/bin
[root@localhost bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server
[root@localhost bin]# 

//加载到PATH 在文件后面添加
export REDIS_HOME=/soft/installdir/redis6
export PATH=$REDIS_HOME/bin:$PATH

设置开机自启动,redis_init_script 位于位于Redis的 /utils/ 目录下,配置号一些启动的脚本位置在该文件内;

//复制该脚本到启动
cp redis_init_script /etc/init.d/redisd

//复制自动启动的配置文件
mkdir /etc/redis
cp redis.conf /etc/redis/6379.conf

//开启开机自启动
chkconfig redisd on

7.安装多个实例

就是在一台服务器上部署多个redis 实例

[root@localhost 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 中这段代码

#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

处理错误后继续执行

[root@localhost 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] 6666   //如果是多个实例就需要指定端口,默认不填是6379  后面只需要一路确认即可
Please select the redis config file name [/etc/redis/6666.conf] 
Selected default - /etc/redis/6666.conf
Please select the redis log file name [/var/log/redis_6666.log] 
Selected default - /var/log/redis_6666.log
Please select the data directory for this instance [/var/lib/redis/6666] 
Selected default - /var/lib/redis/6666
Please select the redis executable path [/soft/installdir/redis6/bin/redis-server] 
Selected config:
Port           : 6666  #####启动端口
Config file    : /etc/redis/6666.conf  #####配置文件
Log file       : /var/log/redis_6666.log  #####日志文件
Data dir       : /var/lib/redis/6666  #####数据目录
Executable     : /soft/installdir/redis6/bin/redis-server  #####可执行脚本
Cli Executable : /soft/installdir/redis6/bin/redis-cli   #####客户端执行脚本
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6666.conf => /etc/init.d/redis_6666
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

两个实例在运行

[root@localhost utils]# ps -ef |grep redis
root       1036      1  0 20:45 ?        00:00:00 /soft/installdir/redis6/bin/redis-server 127.0.0.1:6379
root       1502   1474  0 20:49 pts/0    00:00:00 redis-cli -p 6379
root       1689      1  0 20:55 ?        00:00:00 /soft/installdir/redis6/bin/redis-server 127.0.0.1:6666
root       1695   1509  0 20:55 pts/1    00:00:00 grep --color=auto redis
[root@localhost utils]# redis-cli  -p 6666
127.0.0.1:6666> keys *

你可能感兴趣的:(Redis,redis,缓存)