redis
安装redis
1. 访问官网 https://redis.io/
2. 可以复制该链接,也可以直接下载,我这里用的是直接复制链接
3. yum install wget
Linux下载wget 命令
4. wget https://download.redis.io/releases/redis-6.2.6.tar.gz
5. 解压压缩包 tar xf redis…tar.gz,可以看到下载的redis 非常小
解压之后进入redis…, 一般现在软件安装什么,可以直接看 readme
比如可以告诉你可以如何编译
如果编译出错了也可以使用make distclean
也可以告诉你如何启动redis
默认redis 配置文件安装路径
6. 使用make. (make 是Linux 原有命令,会找Makefile),在src 文件下也有个 真身 makefile 详细说明. 默认安装路
7. 回归正题,直接使用make 命令,安装redis.。 redis-6.2.6目录下
报错gcc, 可以安装
yum install gcc
在使用make distclean
清除安装失败
安装成功可以看到 make test
8. 到src目录下可以直接** ./redis-serve** 启动redis. (这个时候已经生成程序了)
9. 其实到这里我们已经安装成功了,但是我们日常开发过程中肯定不想每次启动都用这个命令
10. make install PREFIX=/opt/redis6
这一步的目的是将可执行程序迁出,不在和源码混在一起
11. 比如我们想使用 service start redis .但是这一步肯定不支持。回到刚才utils 下面,找到install_server.sh
12. 首先我们先j将执行程序添加到环境变量vim /etc/profile
13. source /etc/profile
刷新配置文件,看下配置路径是否正确echo $PATH
14. 使用./install_server.sh
提示报错,这个程序似乎使用systemd
This systems seems to use systemd.
修改 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
注释之后重新运行,一直回车就行,该默认并会添加到开机启动
stackoverflow
解决地址:ttps://stackoverflow.com/questions/61694459/installing-redis-use-install-server-sh
Welcome to the redis service installer
# 这句话意思是一台物理既可以跑多台redis 靠端口号区分
This script will help you easily set up a running redis server
#选择端口号 16379
Please select the redis port for this instance: [6379] 16379
# 16379配置文件放在哪里
Please select the redis config file name [/etc/redis/16379.conf]
Selected default - /etc/redis/16379.conf
# redis_16379 日志文件放在哪里
Please select the redis log file name [/var/log/redis_16379.log]
Selected default - /var/log/redis_16379.log
# redis_16379 数据存放在哪里,磁盘目录存储数据,持久化问题
Please select the data directory for this instance [/var/lib/redis/16379]
Selected default - /var/lib/redis/16379
# 可执行程序路径,因为上面在config里面配置,所以知道该路径
Please select the redis executable path [/opt/redis6/bin/redis-server]
Selected config:
Port : 16379
Config file : /etc/redis/16379.conf
Log file : /var/log/redis_16379.log
Data dir : /var/lib/redis/16379
Executable : /opt/redis6/bin/redis-server
Cli Executable : /opt/redis6/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
# 拷贝临时目录到系统文件中
Copied /tmp/16379.conf => /etc/init.d/redis_16379
# 装机到服务
Installing service...
# 开机启动
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
15. cd /etc/init.d/
可以看到目录下有个 redis_16379 脚本
16. service redis_16379 status 安装完成并附带端口号
17 指定端口登录 redis-cli -p 16379
默认 redis-cli 启动进入639
18 设置密码 config set requirepass XXXX
非永久设置。重启失效
#进入redis 设置
config set requirepass 123456
# 获取密码
config get requirepass
# 登录
auth 123456
永久配置
找到安装cofing /etc/redis/16379.conf
设置完密码之后,每次重启redis 都需要redis -a 123456 stop
可以设置init.d
下面我们安装的redis6379
vi /etc/init.d/redis
$CLIEXEC -a "youpassword" -p $REDISPORT shutdown
也可以使用
vim /etc/init.d/redis_6379
RESDISPASSWORD=“123456”
在下面stop 下加-a
$CLIEXEC -a $RESDISPASSWORD -p $REDISPORT shutdown
解除ip限制绑定
将bind 注释 找到安装cofing /etc/redis/16379.conf