阿里云centos7安装redis

  1. 在centOS里通过wget下载redis wget http://download.redis.io/releases/redis-4.0.9.tar.gz
[root@root local]# wget http://download.redis.io/releases/redis-4.0.9.tar.gz 
--2019-10-28 11:15:35--  http://download.redis.io/releases/redis-4.0.9.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: 1737022 (1.7M) [application/x-gzip]
Saving to: ‘redis-4.0.9.tar.gz’

100%[=====================================================================================================================================================>] 1,737,022   1.04MB/s   in 1.6s   

2019-10-28 11:15:37 (1.04 MB/s) - ‘redis-4.0.9.tar.gz’ saved [1737022/1737022]
  1. 在/usr/local里面创建redis目录(这个是安装目录,自己随意放)
[root@root local]# cd /usr/local
[root@root local]# mkdir redis
  1. 解压到创建的目录
tar -xzvf redis-4.0.9.tar.gz -C /usr/local/redis
[root@root local]# cd redis
[root@root redis]# ls
redis-4.0.9
  1. 进入目录编译一下,用make命令编译一下
cd /usr/local/redis/redis-4.0.9
make

注意:make命令执行完成编译后,会在src目录下生成6个可执行文件,分别是redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-rdb、redis-sentinel。

  1. 将译生成的可执行文件拷贝到/usr/local/bin目录下(这个后期可以直接使用命令);
[root@root src]# cd /usr/local/redis/redis-4.0.9/src
[root@root src]# cp {redis-server,redis-cli,redis-benchmark,redis-check-aof,redis-check-rdb,redis-sentinel} /usr/local/bin
  1. 进入redis-4.0.9执行安装命令 make install
[root@root redis-4.0.9]# make install
cd src && make install
make[1]: Entering directory `/usr/local/redis/redis-4.0.9/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis/redis-4.0.9/src'
make[1]: Entering directory `/usr/local/redis/redis-4.0.9/src'

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/usr/local/redis/redis-4.0.9/src'
  1. 执行基本配置
./utils/install_server.sh

一直点击回车就可以了,中括号里面的是默认配置的路径

[root@root redis-4.0.9]# ./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 [/usr/local/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     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
  1. 查看开机启动列表 chkconfig --list
[root@root redis-4.0.9]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

aegis          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
redis_6379     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
  1. 开启Redis服务操作通过/etc/init.d/redis_6379 start命令,也可通过(service redis_6379 start);
    关闭Redis服务操作通过/etc/init.d/redis_6379 stop命令,也可通过(service redis_6379 stop);
[root@root redis-4.0.9]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@root redis-4.0.9]# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
[root@root redis-4.0.9]# service redis_6379 start
Starting Redis server...
[root@root redis-4.0.9]# service redis_6379 stop
Stopping ...
Redis stopped
  1. 远程登陆redis
[root@root redis-4.0.9]# cd /etc/redis

编辑 6379.conf

vim 6379.conf

在bind 127.0.0.1前加“#”将其注释掉

# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1

如果远程访问失败,修改安装redis服务时的配置文件中把127.0.0.1 改为0.0.0.0,然后重启服务即可(配置文件过长vim修改可能不好找,建议拖到本地修改上传)

# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1
bind 0.0.0.0

默认为保护模式,把 protected-mode yes 改为 protected-mode no

# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

默认为不守护进程模式,把daemonize no 改为daemonize yes

# 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

将 requirepass foobared前的“#”去掉,密码改为你想要设置的密码

# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass 123456

然后使用Redis客户端登陆,如果登陆失败,查看自己阿里云6379的端口是否开启

  1. 这时虽然连接成功了,但是会有一个问题,就是在服务器你使用关闭命令时会出现
    (error) NOAUTH Authentication required.错误,这是由于配置了密码以后,关闭的时候没有密码,所以会关闭不了。找到/etc/init.d/redis_6379文件,修改一下代码
[root@root redis]# vim /etc/init.d/redis_6379
$CLIEXEC -a "123456" -p $REDISPORT shutdown
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值