前言
- 简单粗暴复制黏贴搭建好 Redis,末尾有常见问题处理方式。
步骤
- 第一步 下载、解压
- 第二步 编译前环境准备工作
- 第三步 编译、编译安装
- 第四步 执行install_server.sh
- 第五步 查看 Redis 已经启动
- 第六步 开启远程连接
- 第七步 常用命令
- 第八步 常用参数
- 第九步 连接工具
- 第十步 错误解决 经典
第一步 下载、解压
- 下载
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
- 解压
tar -zxvf redis-6.0.6.tar.gz
- 进reids 目录cd
cd /root/redis-6.0.6
第二步 编译前环境准备工作
- 更新 git 版本
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
gcc -v
- 修改下配置文件, 注释一部分代码
vim ./utils/install_server.sh
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
# echo "This systems seems to use systemd."
# echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
# exit 1
#fi
第三步 编译、编译安装
- 编译 make
- 编译安装 make install
# 安装结果
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
第四步 执行install_server.sh
- 命令 utils/install_server.sh
# 配置信息记录
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 已经启动
# 命令 ps -ef | grep redis
root 28206 1 0 07:51 ? 00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
root 28454 21344 0 07:51 pts/0 00:00:00 grep --color=auto redis
第六步 开启远程连接
- 默认的配置文件进行修改 vim /etc/redis/6379.conf
- 开发远程登录 0.0.0.0 表示任意ip都可以访问。
bind 127.0.0.1 改为 bind 0.0.0.0
- 后台启动
daemonize yes
- 重启 -> 先关闭,后启动。
第七步 常用命令
作用 | 命令 |
---|---|
server启动 | src/redis-server /etc/redis/6379.conf |
server关闭 | src/redis-cli shutdown |
client启动 | src/redis-cli -h 指定ip -p 指定端口 -a 指定密码 |
第八步 常用参数
作用 | 命令 |
---|---|
设置reids密码 | redis-cli 执行 config set requirepass password |
redis-cli输入密码 | redis-cli 执行 auth password |
第九步 连接工具
https://gitee.com/MaxBill/RedisPlus
第十步 错误解决 经典
- 经典 https://www.cnblogs.com/operationhome/p/10342258.html
- 经典 https://www.codenong.com/cs106279492
- 经典 http://iambigboss.top/post/76332_1_1.html
错误1
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/root/Redis/redis-5.0.5/src'
make: *** [test] Error 2
解决:yum install tcl
make distclean && make
错误2
make[1]: *** [server.o] 错误 1
make[1]: 离开目录“/root/redis-6.0.8/src”
make: *** [all] 错误 2
原因:GCC版本太低了
解决方法:升级到最新的 9.x.x版本
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
gcc -v
错误3
Welcome to the redis service installer
This script will help you easily set up a running redis server
This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
解决方法:修改下配置文件, 注释一部分代码
vim ./utils/install_server.sh
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
# echo "This systems seems to use systemd."
# echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
# exit 1
#fi