redis的安装

下载安装包

 tar zxvf redis-3.2.9.tar.gz 

cd redis-3.2.9

make

make test & make install

 

cp utils /usr/local

直接在解压目录执行

./install_server.sh

[root@zhu4 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] 7000
Please select the redis config file name [/etc/redis/7000.conf]
Selected default - /etc/redis/7000.conf
Please select the redis log file name [/var/log/redis_7000.log]
Selected default - /var/log/redis_7000.log
Please select the data directory for this instance [/var/lib/redis/7000]
Selected default - /var/lib/redis/7000
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 7000
Config file : /etc/redis/7000.conf
Log file : /var/log/redis_7000.log
Data dir : /var/lib/redis/7000
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/7000.conf => /etc/init.d/redis_7000
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

 

vim /etc/init.d/redis_7000 将下边的三行 复制到上面

 

 chkconfig redis_7000 on --level 2345

 chkconfig redis_7000 --list

redis_7000 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@zhu4 utils]# /etc/init.d/redis_7000 start
Starting Redis server...
[root@zhu4 utils]#
[root@zhu4 utils]# /etc/init.d/redis_7000 status
Redis is running (25648)

 

客户端连接方式

/usr/local/bin/redis-cli -p 7000  本地连接 

/usr/local/bin/redis-cli -h 127.0.0.1 -p 7000     此处的IP需要在配置文件中匹配到才可以   bind 127.0.0.1

/usr/local/bin/redis-cli -h 192.168.1.55 -p 7000    此处的IP需要在配置文件中匹配到才可以   bind 192.168.1.55

如果redis设置有密码 则需要连接进去后 执行以下操作

auth 密码     (密码在配置文件中设置) 之后便可以采取相应操作

set key1 value1

get key1

value1

或者在连接的时候加上  -a 参数

/usr/local/bin/redis-cli -h 192.168.1.55 -p 7000 -a redis(你的密码,这里我的密码为redis)

连接进去后 输入info可以获取更详细的信息

或者在连接的时候加上 info

/usr/local/bin/redis-cli -h 192.168.1.55 -p 7000 info

 

ls  /etc/redis/7000.conf   配置文件

 

[root@zhu4 utils]# redis-server -h   帮助命令
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>

Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel

 

/etc/init.d/redis_7000 start|stop|status|restart  启动命令

或者 redis-server /etc/init.d/redis_7000 方式启动

redis-cli -p 7000 shutdown 把 7000端口的redis停止

默认数据库为16个(从0开始,0-15),默认的数据库就为0

 

redis的监控

-Sentinel 

Sentinel 是redis自带的工具,它可以对redis主从复制进行监控,并实现主挂掉后的自动故障转移

,在转移的过程中,它还可以被配置去执行一个用户自定义脚本,在脚本中我们就能够实现报警通知等功能

 

cp /opt/package/redis-3.2.9/sentinel.conf /etc/redis/

/usr/local/bin/redis-sentinel -h  帮助文档 

redis-server /etc/redis/sentinel.conf --sentinel

 

转载于:https://www.cnblogs.com/yingdiblog/p/7111065.html

### 安装 Redis 数据库 Redis 是一个高性能的开源内存数据库,支持多种数据结构,适用于缓存、实时分析、消息队列等应用场景。以下是 Redis 在不同操作系统上的安装方法。 #### 在 Linux 系统上安装 Redis 1. **下载 Redis** 首先,访问 Redis 官网下载最新版本的源代码包。使用 `wget` 命令下载: ```bash wget https://download.redis.io/redis-stable.tar.gz ``` 2. **解压文件** 解压下载的压缩包,并进入解压后的目录: ```bash tar -zxvf redis-stable.tar.gz cd redis-stable ``` 3. **编译 Redis** 使用 `make` 命令编译 Redis 源代码。如果系统中没有安装 `gcc` 编译器,可以先通过以下命令安装: ```bash sudo apt-get install build-essential ``` 然后进行编译: ```bash make ``` 4. **安装 Redis** 编译完成后,执行 `make install` 命令将 Redis 安装到系统目录中: ```bash sudo make install ``` 5. **配置 Redis** 默认情况下,Redis 的配置文件 `redis.conf` 位于源代码目录中。可以将其复制到 `/etc/redis` 目录下,并修改配置文件中的 `daemonize` 参数为 `yes`,以便以后台模式运行 Redis: ```bash sudo cp redis.conf /etc/redis/ sudo nano /etc/redis/redis.conf ``` 6. **启动 Redis** 修改完配置文件后,可以通过以下命令启动 Redis: ```bash redis-server /etc/redis/redis.conf ``` 7. **测试 Redis** 使用 `redis-cli` 工具连接到 Redis 服务器,并执行简单的命令进行测试: ```bash redis-cli ping ``` 如果返回 `PONG`,则表示 Redis 服务器已经成功启动。 #### 在 Windows 系统上安装 Redis 1. **下载 Redis Windows 版本** Redis 官方并不直接提供 Windows 版本的安装包,但可以从 Microsoft 的 GitHub 仓库下载适用于 Windows 的 Redis: ```bash https://github.com/microsoftarchive/redis/releases ``` 2. **安装 Redis** 下载完成后,解压压缩包,并将解压后的文件夹移动到一个合适的位置,例如 `C:\Redis`。 3. **启动 Redis** 进入 Redis 目录,执行 `redis-server.exe` 文件启动 Redis 服务器: ```bash cd C:\Redis redis-server.exe ``` 如果没有指定配置文件,Redis 将使用默认配置启动。为了避免错误,建议创建一个 `redis.conf` 配置文件,并通过以下命令启动 Redis: ```bash redis-server.exe redis.conf ``` 4. **测试 Redis** 使用 `redis-cli.exe` 工具连接到 Redis 服务器,并执行简单的命令进行测试: ```bash redis-cli.exe ping ``` 如果返回 `PONG`,则表示 Redis 服务器已经成功启动。 #### 在 macOS 系统上安装 Redis 1. **使用 Homebrew 安装 Redis** 如果你使用的是 macOS,并且已经安装了 Homebrew,可以直接通过以下命令安装 Redis: ```bash brew install redis ``` 2. **启动 Redis** 安装完成后,可以通过以下命令启动 Redis 服务: ```bash brew services start redis ``` 3. **测试 Redis** 使用 `redis-cli` 工具连接到 Redis 服务器,并执行简单的命令进行测试: ```bash redis-cli ping ``` 如果返回 `PONG`,则表示 Redis 服务器已经成功启动。 #### 注意事项 - 在生产环境中,建议使用后台模式启动 Redis,并配置合适的持久化策略,以确保数据的安全性[^3]。 - 如果在 Windows 上启动 Redis 时遇到端口冲突问题,可以检查是否有其他程序占用了 6379 端口,或者尝试更改 Redis 的监听端口[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值