Linux上安装Redis并搭建集群(一)

一、安装Redis

0、搭建环境
虚拟机:VMware 10.0.2
Linux系统:CentOS-6.5
SSH客户端:Xshell 6
1、安装redist需要安装支持包,yum install gcc-c++
2、redis安装包采取的是在线wget下载.若wget命令不存在,执行 yum -y install wget安装
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
3、解压在当前目录(我的是家目录)
[root@localhost~]# tar -zxvf redis-5.0.3.tar.gz 
4、编译并安装 (redis安装程序是c语言编写,需要编译转换后才能安装)
  [root@localhost redis-4.0.9]# make && make PREFIX=/usr/local/redis install

1).&&连接两个命令,前面命令的返回值决定是否执行后面的命令。
2).PREFIX(注意:大写)指定安装目录,若目录不存在,则自动创建

5、复制配置文件并修改

复制安装包下 redis.conf 到 目录/usr/local/redis下

vim redis.conf

修改:

 bind 127.0.0.1 ---->bind 自己ip

 daemonize no   no---->yes

 protected-mode yes   yes---->no
6、配置环境变量并开启redis防火墙端口
7、启动Redis

1).前端启动

[root@localhost ~]# cd /usr/local
[root@localhost local]# ll
总用量 40
drwxr-xr-x. 2 root root 4096 9月  23 2011 bin
drwxr-xr-x. 2 root root 4096 9月  23 2011 etc
drwxr-xr-x. 2 root root 4096 9月  23 2011 games
drwxr-xr-x. 2 root root 4096 9月  23 2011 include
drwxr-xr-x. 2 root root 4096 9月  23 2011 lib
drwxr-xr-x. 2 root root 4096 9月  23 2011 libexec
drwxr-xr-x. 3 root root 4096 1月  28 03:06 redis
drwxr-xr-x. 2 root root 4096 9月  23 2011 sbin
drwxr-xr-x. 5 root root 4096 12月 12 05:53 share
drwxr-xr-x. 2 root root 4096 9月  23 2011 src
[root@localhost local]# cd redis
[root@localhost redis]# ll
总用量 72
drwxr-xr-x. 2 root root  4096 1月  28 01:19 bin
-rw-r--r--. 1 root root   416 1月  28 03:06 dump.rdb
-rw-r--r--. 1 root root 62155 1月  28 01:22 redis.conf
[root@localhost redis]# cd bin
[root@localhost bin]# ll
总用量 47500
-rw-r--r--. 1 root root       92 1月  28 01:19 dump.rdb
-rwxr-xr-x. 1 root root  8173746 1月  28 00:55 redis-benchmark
-rwxr-xr-x. 1 root root 10659192 1月  28 00:55 redis-check-aof
-rwxr-xr-x. 1 root root 10659192 1月  28 00:55 redis-check-rdb
-rwxr-xr-x. 1 root root  8473359 1月  28 00:55 redis-cli
lrwxrwxrwx. 1 root root       12 1月  28 00:55 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 10659192 1月  28 00:55 redis-server
[root@localhost bin]# ./redis-server
1809:C 29 Jan 2019 05:36:15.592 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1809:C 29 Jan 2019 05:36:15.593 # Redis version=5.0.3, bits=32, commit=00000000, modified=0, pid=1809, just started
1809:C 29 Jan 2019 05:36:15.593 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
1809:M 29 Jan 2019 05:36:15.598 * Increased maximum number of open files to 10032 (it was originally set to 1024).
1809:M 29 Jan 2019 05:36:15.624 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 32 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1809
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

1809:M 29 Jan 2019 05:36:15.635 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1809:M 29 Jan 2019 05:36:15.635 # Server initialized
1809:M 29 Jan 2019 05:36:15.635 # 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.
1809:M 29 Jan 2019 05:36:15.652 * DB loaded from disk: 0.016 seconds
1809:M 29 Jan 2019 05:36:15.652 * Ready to accept connections

我们一般都是采用后端来启动Redis,所以需要使用ctrl+c停止前端启动,下面来介绍后端启动:

2).后端启动

[root@localhost bin]# cd ..
[root@localhost redis]# ll
总用量 72
drwxr-xr-x. 2 root root  4096 1月  29 05:36 bin
-rw-r--r--. 1 root root   416 1月  28 03:06 dump.rdb
-rw-r--r--. 1 root root 62155 1月  28 01:22 redis.conf
[root@localhost redis]# vim redis.conf 

按i键将redis.conf中的
daemonize no no---->yes
改为yes以后,按esc退出,再按:wq 保存

[root@localhost redis]# ll
总用量 68
drwxr-xr-x. 2 root root  4096 1月  29 05:36 bin
-rw-r--r--. 1 root root 62155 1月  29 05:42 redis.conf
[root@localhost redis]# ./bin/redis-server ./redis.conf 
1838:C 29 Jan 2019 05:46:37.468 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1838:C 29 Jan 2019 05:46:37.468 # Redis version=5.0.3, bits=32, commit=00000000, modified=0, pid=1838, just started
1838:C 29 Jan 2019 05:46:37.468 # Configuration loaded
[root@localhost redis]# ps -ef | grep -i redis
root      1839     1  0 05:46 ?        00:00:00 ./bin/redis-server 127.0.0.1:6379
root      1845  1676  2 05:47 pts/0    00:00:00 grep -i redis

在这里插入图片描述

./bin/redis-server ./redis.conf (后端启动命令)
ps -ef | grep -i redis (查看redis是否启动成功)
./bin/redis-server 127.0.0.1:6379 (显示这条说明已经成功,默认是在6379端口上)

[root@localhost redis]# ./bin/redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 

连的是当前主机的6379,客服端可以输入命令ping,服务端回一个pong;那说明客户端和服务端可以进行通信了。

8、停止Redis
1).# kill -9 1839  (一般不建议使用直接杀死进程)

2).# ./bin/redis-cli shutdown

下一篇:Linux上安装Redis并搭建集群(二)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

老周聊架构

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

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

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

打赏作者

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

抵扣说明:

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

余额充值