centos6 redis4版本 安装和启动步骤(二)

一、 安装环境信息

Linux 操作系统: centos6.1

Redis版本:redis-4.0.6.tar.gz

二、redis 安装

第一步:获取redis安装包到路径
1)官网地址 :https://redis.io/ ,下载reids安装包

2)通过wget http://download.redis.io/releases/redis-4.0.6.tar.gz 在线下载redis安装包

以下用wget获取安装包并安装redis服务:

[root@zero tools]# wget http://download.redis.io/releases/redis-4.0.6.tar.gz
--2019-07-01 13:51:30--  http://download.redis.io/releases/redis-4.0.6.tar.gz
Resolving download.redis.io... 109.74.203.151
Connecting to download.redis.io|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1723533 (1.6M) [application/x-gzip]
Saving to: “redis-4.0.6.tar.gz”

100%[===================================================================================================================>] 1,723,533   10.2K/s   in 2m 50s  

2019-07-01 13:54:21 (9.88 KB/s) - “redis-4.0.6.tar.gz” saved [1723533/1723533]

第二步:解压压缩包

[root@zero tools]# tar -zxvf  redis-4.0.6.tar.gz

[root@zero tools]# ll
total 56124
drwxrwxr-x. 6 root root     4096 Dec  5  2017 redis-4.0.6
-rw-r--r--. 1 root root  1723533 Dec  5  2017 redis-4.0.6.tar.gz

第三步:redis安装需要gcc依赖,需要先安装完成在安装reids服务,通过在线安装gcc依赖,直接通过yum安装gcc依赖

[root@zero tools]# yum install gcc

Dependencies Resolved

=============================================================================================================================================================
 Package                                 Arch                            Version                                      Repository                        Size
=============================================================================================================================================================
Installing:
 gcc                                     x86_64                          4.4.7-23.el6                                 base                              10 M
Installing for dependencies:
 cloog-ppl                               x86_64                          0.15.7-1.2.el6                               base                              93 k
 cpp                                     x86_64                          4.4.7-23.el6                                 base                             3.7 M
 glibc-devel                             x86_64                          2.12-1.212.el6_10.3                          updates                          991 k
 glibc-headers                           x86_64                          2.12-1.212.el6_10.3                          updates                          620 k
 kernel-headers                          x86_64                          2.6.32-754.15.3.el6                          updates                          4.6 M
 mpfr                                    x86_64                          2.4.1-6.el6                                  base                             157 k
 ppl                                     x86_64                          0.10.2-11.el6                                base                             1.3 M
Updating for dependencies:
 glibc                                   x86_64                          2.12-1.212.el6_10.3                          updates                          3.8 M
 glibc-common                            x86_64                          2.12-1.212.el6_10.3                          updates                           14 M
 libgcc                                  x86_64                          4.4.7-23.el6                                 base                             104 k
 libgomp                                 x86_64                          4.4.7-23.el6                                 base                             135 k
 tzdata                                  noarch                          2019a-1.el6                                  updates                          513 k

Transaction Summary
=============================================================================================================================================================
Install       8 Package(s)
Upgrade       5 Package(s)
ownloading Packages:
(1/13): cloog-ppl-0.15.7-1.2.el6.x86_64.rpm                                                                                           |  93 kB     00:00     
(2/13): cpp-4.4.7-23.el6.x86_64.rpm                                                                                                   | 3.7 MB     00:06     
(3/13): gcc-4.4.7-23.el6.x86_64.rpm                                                                                                   |  10 MB     00:17     
(4/13): glibc-2.12-1.212.el6_10.3.x86_64.rpm                                                                                          | 3.8 MB     00:06     
(5/13): glibc-common-2.12-1.212.el6_10.3.x86_64.rpm                                                                                   |  14 MB     00:27     
(6/13): glibc-devel-2.12-1.212.el6_10.3.x86_64.rpm                                                                                    | 991 kB     00:01     
(7/13): glibc-headers-2.12-1.212.el6_10.3.x86_64.rpm                                                                                  | 620 kB     00:01     
(8/13): kernel-headers-2.6.32-754.15.3.el6.x86_64.rpm                                                                                 | 4.6 MB     00:08     
(9/13): libgcc-4.4.7-23.el6.x86_64.rpm                                                                                                | 104 kB     00:00     
(10/13): libgomp-4.4.7-23.el6.x86_64.rpm                                                                                              | 135 kB     00:00     
(11/13): mpfr-2.4.1-6.el6.x86_64.rpm                                                                                                  | 157 kB     00:00     
(12/13): ppl-0.10.2-11.el6.x86_64.rpm                                                                                                 | 1.3 MB     00:01     
(13/13): tzdata-2019a-1.el6.noarch.rpm  
Installed:
  gcc.x86_64 0:4.4.7-23.el6                                                                                                                                  

Dependency Installed:
  cloog-ppl.x86_64 0:0.15.7-1.2.el6           cpp.x86_64 0:4.4.7-23.el6 glibc-devel.x86_64 0:2.12-1.212.el6_10.3 glibc-headers.x86_64 0:2.12-1.212.el6_10.3
  kernel-headers.x86_64 0:2.6.32-754.15.3.el6 mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6              

Dependency Updated:
  glibc.x86_64 0:2.12-1.212.el6_10.3      glibc-common.x86_64 0:2.12-1.212.el6_10.3      libgcc.x86_64 0:4.4.7-23.el6      libgomp.x86_64 0:4.4.7-23.el6     
  tzdata.noarch 0:2019a-1.el6            

Complete!

第三步:编译安装

[root@zero redis]# make MALLOC=libc
cd src && make all
make[1]: Entering directory `/usr/local/redis/src'
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/usr/local/redis/src'

三、启动redis的三种方式

切换当前到目录到redis/src 路径下:

[root@zero redis]# cd src/
[root@zero src]# 

1、直接执行./redis-server 启动redis服务

[root@zero src]# ./redis-server 
19836:C 27 Jun 16:02:05.388 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
19836:C 27 Jun 16:02:05.388 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=19836, just started
19836:C 27 Jun 16:02:05.388 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
19836:M 27 Jun 16:02:05.388 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 19836
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

19836:M 27 Jun 16:02:05.389 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
19836:M 27 Jun 16:02:05.389 # Server initialized
19836:M 27 Jun 16:02:05.389 # 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.
19836:M 27 Jun 16:02:05.389 * DB loaded from disk: 0.000 seconds
19836:M 27 Jun 16:02:05.389 * Ready to accept connections

备注:最直接到启动方式,但这种方式不建议使用,启动服务以后服务redis窗口就不能关闭,窗口需要一直开着,导致关闭窗口就会停止redis服务

2、以后台进程方式启动redis服务

第一步:修改redis.conf文件
打开redis到配置文件redis.conf文件,找到daemonize属性值

[root@zero redis]# vim  redis.comf 

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# 修改下面到 daemonize 属性值为 yes ,默认配置no不为默认守护进程
daemonize yes  


:wq

修改配置文件保存:wq 保存退出当前文件

第二步:启动redis ,通过制定配置文件redis.conf

[root@zero redis]# src/redis-server redis.conf 
20169:C 27 Jun 16:09:38.423 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
20169:C 27 Jun 16:09:38.423 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=20169, just started
20169:C 27 Jun 16:09:38.423 # Configuration loaded

查看当前reids是否启动成功

[root@zero redis]# ps -ef|grep redis
root     20170     1  0 16:09 ?        00:00:00 src/redis-server 127.0.0.1:6379
root     20175 16254  0 16:09 pts/1    00:00:00 grep redis
[root@zero redis]# 

可以看到有一个20170到进程,同时可以通过redis客户端操作看是否正到启动成功

[root@zero redis]# ./src/redis-cli 
127.0.0.1:6379> set key1 value1
OK
127.0.0.1:6379> get key1 
"value1"
127.0.0.1:6379> 

以上操作可以对redis 数据到添加和获取

使用kill命令结束刚刚启动到redis后台进程

[root@zero redis]# kill  -9  20170      

3、设置redis开机自启动,也是推荐到一种启动方式

1、在/etc目录下新建redis目录

[root@zero etc]# mkdir redis   

2、将/usr/local/redis-4.0.6/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf

[root@zero etc]# cp /usr/local/redis/redis.conf  redis/6379.conf

3、将redis的启动脚本复制一份放到/etc/init.d目录下

[root@zero etc]# cp /usr/local/redis/utils/redis_init_script init.d/redisd

4、设置redis开机自启动,先切换到/etc/init.d目录下执行自启命令

[root@zero etc]# chkconfig redisd on
service redisd does not support chkconfig

结果显示是redisd不支持chkconfig

解决方法:

使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出

# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database

注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。

再次执行开机自启命令,成功

[root@zero etc]# chkconfig redisd on

现在可以直接已服务的形式启动和关闭redis了

启动:service redisd start

[root@zero etc]# service redisd start
Starting Redis server...
20898:C 27 Jun 16:23:30.305 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
20898:C 27 Jun 16:23:30.305 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=20898, just started
20898:C 27 Jun 16:23:30.305 # Configuration loaded
[root@zero etc]# ps -ef|grep redis
root     20899     1  0 16:23 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379      
root     20904 16254  0 16:23 pts/1    00:00:00 grep redis

关闭:service redisd stop

root@zero etc]# service redisd stop
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值