Centos7安装Redis单节点

下载Redis安装包

Redis官网地址:https://redis.io/
在这里插入图片描述
这里下载最新的5.0.5版本。下载地址:http://download.redis.io/releases/redis-5.0.5.tar.gz

服务器中使用wget直接下载

服务器需要能够访问外网,可以参考VirtualBox配置Centos7固定IP和外网访问:https://blog.csdn.net/iceliooo/article/details/102802994

在/usr/local/software目录下载redis-5.0.5.tar.gz

[root@k8s-master ~]# cd /usr/local/
[root@k8s-master local]# mkdir software
[root@k8s-master local]# cd software/
[root@k8s-master software]# pwd
/usr/local/software
[root@k8s-master software]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
-bash: wget: command not found

没有wget需要先安装wget

[root@k8s-master software]# yum -y install wget
Loaded plugins: fastestmirror
base                                                                                                                         | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                                                                                               
··················
Complete!

重新下载

[root@k8s-master software]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
--2019-11-04 10:39:49--  http://download.redis.io/releases/redis-5.0.5.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1975750 (1.9M) [application/x-gzip]
Saving to: ‘redis-5.0.5.tar.gz’
················
2019-11-04 10:41:05 (25.8 KB/s) - ‘redis-5.0.5.tar.gz’ saved [1975750/1975750] 
[root@k8s-master software]# 

解压

[root@k8s-master software]# ll
total 1932
-rw-r--r-- 1 root root 1975750 May 16 00:26 redis-5.0.5.tar.gz
[root@k8s-master software]# tar -zxvf redis-5.0.5.tar.gz 
redis-5.0.5/
········
drwxrwxr-x 6 root root     334 May 16 00:07 redis-5.0.5
-rw-r--r-- 1 root root 1975750 May 16 00:26 redis-5.0.5.tar.gz
[root@k8s-master software]# cd redis-5.0.5
[root@k8s-master redis-5.0.5]# ll
total 264
-rw-rw-r--  1 root root 106874 May 16 00:07 00-RELEASENOTES
-rw-rw-r--  1 root root     53 May 16 00:07 BUGS
-rw-rw-r--  1 root root   2381 May 16 00:07 CONTRIBUTING
-rw-rw-r--  1 root root   1487 May 16 00:07 COPYING
drwxrwxr-x  6 root root    124 May 16 00:07 deps
-rw-rw-r--  1 root root     11 May 16 00:07 INSTALL
-rw-rw-r--  1 root root    151 May 16 00:07 Makefile
-rw-rw-r--  1 root root   6888 May 16 00:07 MANIFESTO
-rw-rw-r--  1 root root  20555 May 16 00:07 README.md
-rw-rw-r--  1 root root  61797 May 16 00:07 redis.conf
-rwxrwxr-x  1 root root    275 May 16 00:07 runtest
-rwxrwxr-x  1 root root    280 May 16 00:07 runtest-cluster
-rwxrwxr-x  1 root root    341 May 16 00:07 runtest-moduleapi
-rwxrwxr-x  1 root root    281 May 16 00:07 runtest-sentinel
-rw-rw-r--  1 root root   9710 May 16 00:07 sentinel.conf
drwxrwxr-x  3 root root   4096 May 16 00:07 src
drwxrwxr-x 11 root root    182 May 16 00:07 tests
drwxrwxr-x  8 root root   4096 May 16 00:07 utils

安装gcc依赖

Redis由C语言编写,需要gcc依赖包

[root@k8s-master redis-5.0.5]# yum -y install gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
·········
Installed:
  gcc.x86_64 0:4.8.5-39.el7                                                                                                                         

Dependency Installed:
  cpp.x86_64 0:4.8.5-39.el7    glibc-devel.x86_64 0:2.17-292.el7  glibc-headers.x86_64 0:2.17-292.el7  kernel-headers.x86_64 0:3.10.0-1062.4.1.el7 
  libmpc.x86_64 0:1.0.1-3.el7  mpfr.x86_64 0:3.1.1-4.el7         

Dependency Updated:
  glibc.x86_64 0:2.17-292.el7       glibc-common.x86_64 0:2.17-292.el7       libgcc.x86_64 0:4.8.5-39.el7       libgomp.x86_64 0:4.8.5-39.el7      

Complete!

编译&安装

编译

[root@k8s-master redis-5.0.5]# pwd
/usr/local/software/redis-5.0.5
[root@k8s-master redis-5.0.5]# make MALLOC=libc
cd src && make all
make[1]: Entering directory `/usr/local/software/redis-5.0.5/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/software/redis-5.0.5/src'
make[1]: Entering directory `/usr/local/software/redis-5.0.5/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
(cd ../deps && make distclean)
make[2]: Entering directory `/usr/local/software/redis-5.0.5/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/usr/local/software/redis-5.0.5/deps'
(rm -f .make-*)
·········
Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/usr/local/software/redis-5.0.5/src'
[root@k8s-master redis-5.0.5]#

安装
将/usr/local/software/redis-5.0.5/src目录下二进制文件安装到/usr/local/bin

[root@k8s-master ~]# cd /usr/local/bin
[root@k8s-master bin]# ll
total 0
[root@k8s-master bin]# 
[root@k8s-master redis-5.0.5]# pwd
/usr/local/software/redis-5.0.5
[root@k8s-master redis-5.0.5]# cd src
[root@k8s-master src]# make install
    CC Makefile.dep

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@k8s-master src]# 

修改默认配置文件

默认配置文件:/usr/local/software/redis-5.0.5/redis.conf

[root@k8s-master src]# cd ..
[root@k8s-master redis-5.0.5]# ll
total 268
-rw-rw-r--  1 root root 106874 May 16 00:07 00-RELEASENOTES
-rw-rw-r--  1 root root     53 May 16 00:07 BUGS
-rw-rw-r--  1 root root   2381 May 16 00:07 CONTRIBUTING
-rw-rw-r--  1 root root   1487 May 16 00:07 COPYING
drwxrwxr-x  6 root root    192 Nov  4 10:53 deps
-rw-rw-r--  1 root root     11 May 16 00:07 INSTALL
-rw-rw-r--  1 root root    151 May 16 00:07 Makefile
-rw-rw-r--  1 root root   6888 May 16 00:07 MANIFESTO
-rw-rw-r--  1 root root  20555 May 16 00:07 README.md
-rw-rw-r--  1 root root  61797 May 16 00:07 redis.conf
-rwxrwxr-x  1 root root    275 May 16 00:07 runtest
-rwxrwxr-x  1 root root    280 May 16 00:07 runtest-cluster
-rwxrwxr-x  1 root root    341 May 16 00:07 runtest-moduleapi
-rwxrwxr-x  1 root root    281 May 16 00:07 runtest-sentinel
-rw-rw-r--  1 root root   9710 May 16 00:07 sentinel.conf
drwxrwxr-x  3 root root   8192 Nov  4 10:58 src
drwxrwxr-x 11 root root    182 May 16 00:07 tests
drwxrwxr-x  8 root root   4096 May 16 00:07 utils
[root@k8s-master redis-5.0.5]# pwd
/usr/local/software/redis-5.0.5
[root@k8s-master redis-5.0.5]# cp redis.conf redis.conf.bak

修改为后台启动daemonize no修改为daemonize yes

134 # By default Redis does not run as a daemon. Use 'yes' if you need it.
135 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
136 daemonize yes

修改访问限制:默认只能本机访问。bind 127.0.0.1注释掉或者修改为bind 0.0.0.0

67 # JUST COMMENT THE FOLLOWING LINE.
68 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 # bind 127.0.0.1

设置访问密码,默认密码为空,取消requirepass的注释,添加requirepass yourpassword

507 # requirepass foobared
508 requirepass ******

启动Redis

[root@k8s-master redis-5.0.5]# vi redis.conf
[root@k8s-master redis-5.0.5]# cd src
[root@k8s-master src]# redis-server ../redis.conf
21189:C 04 Nov 2019 11:17:00.847 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21189:C 04 Nov 2019 11:17:00.847 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=21189, just started
21189:C 04 Nov 2019 11:17:00.847 # Configuration loaded
[root@k8s-master src]# 

连接客户端

如果设置了密码会提示(error) NOAUTH Authentication required,需要输入密码才能正常访问

[root@k8s-master src]# redis-cli 
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth ******
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> 

停止Redis

客户端中停止:

127.0.0.1:6379> shutdown
not connected> 

使用kill

[root@k8s-master src]# ps -ef|grep redis
root     24115     1  0 11:22 ?        00:00:00 redis-server *:6379
root     24208 29823  0 11:23 pts/0    00:00:00 grep --color=auto redis
[root@k8s-master src]# ps -aux|grep redis
root     24115  0.0  0.1 144020  2028 ?        Ssl  11:22   0:00 redis-server *:6379
root     24310  0.0  0.0 112712   960 pts/0    S+   11:23   0:00 grep --color=auto redis
[root@k8s-master src]# kill -9 24115
[root@k8s-master src]# ps -aux|grep redis
root     24858  0.0  0.0 112712   960 pts/0    S+   11:24   0:00 grep --color=auto redis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值