Linux离线安装Redis

系统环境和版本说明

Linux依然使用的是Centos7,安装的redis是官网的最新的版本4.0.2

安装步骤

下载安装包:
https://redis.io/download

创建文件目录:
# mkdir /usr/local/redis
解压文件
# tar xvfz redis-4.0.2.tar.gz
进入解压文件
# cd /usr/local/redis/redis-4.0.2/
# ls
总用量 280
-rw-rw-r--.  1 root root 131381 921 22:12 00-RELEASENOTES
-rw-rw-r--.  1 root root     53 921 22:12 BUGS
-rw-rw-r--.  1 root root   1815 921 22:12 CONTRIBUTING
-rw-rw-r--.  1 root root   1487 921 22:12 COPYING
drwxrwxr-x.  6 root root   4096 921 22:12 deps
-rw-rw-r--.  1 root root     11 921 22:12 INSTALL
-rw-rw-r--.  1 root root    151 921 22:12 Makefile
-rw-rw-r--.  1 root root   4223 921 22:12 MANIFESTO
-rw-rw-r--.  1 root root  20530 921 22:12 README.md
-rw-rw-r--.  1 root root  57764 921 22:12 redis.conf
-rwxrwxr-x.  1 root root    271 921 22:12 runtest
-rwxrwxr-x.  1 root root    280 921 22:12 runtest-cluster
-rwxrwxr-x.  1 root root    281 921 22:12 runtest-sentinel
-rw-rw-r--.  1 root root   7606 921 22:12 sentinel.conf
drwxrwxr-x.  3 root root   4096 921 22:12 src
drwxrwxr-x. 10 root root   4096 921 22:12 tests
drwxrwxr-x.  8 root root   4096 921 22:12 utils
配置编译环境
# yum install gcc-c++
编译
# make

如果报错:jemalloc/jemalloc.h:没有那个文件或目录
使用:

make MALLOC=libc
# make install
cd src && make install
make[1]: 进入目录“/usr/local/redis/redis-4.0.2/src”
    CC Makefile.dep
make[1]: 离开目录“/usr/local/redis/redis-4.0.2/src”
make[1]: 进入目录“/usr/local/redis/redis-4.0.2/src”
 
Hint: It's a good idea to run 'make test' ;)
 
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: 离开目录“/usr/local/redis/redis-4.0.2/src”

启动Redis-server

# redis-server

Ctrl+shift+t 重开一个终端tab
查看Redis

$ ps -ef | grep redis
root       5188   3749  0 22:46 pts/0    00:00:00 redis-server *:6379
xcx        5235   5200  0 22:46 pts/1    00:00:00 grep --color=auto redis
 

启动Redis-client

$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
 

基本安装完成

此时重启系统,发现redis并没有启动,所以需要设置redis自启,
这里我们进入utils文件夹

# cd /usr/local/redis/redis-4.0.2/utils

切换root用户,执行里面的install_server.sh该文件会帮助我们将redis服务添加到系统自启服务中

# ./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!
 

这是再重启系统,就会发现redis跟随系统自动启动了

如果需要外部访问,需要修改配置文件:

# vim /etc/redis/6379.conf
#bind 127.0.0.1
bind 0.0.0.0
#daemonize no
daemonize yes

防火墙开放6379端口

# firewall-cmd --permanent --zone=public --add-port=6379/tcp
# firewall-cmd --reload

重启redis服务后就可以外部访问了
已导出PDF,下载后方便线下查看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

推到油瓶不扶

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

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

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

打赏作者

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

抵扣说明:

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

余额充值