一、准备工作
- 下载
redis
安装包, 放到root
目录里面下载地址 在 /usr/local/ 下创建 redis ⽂件夹并进⼊
cd /usr/local/ mkdir redis cd redis
将
redis
安装包解压到/usr/local/redis
tar -zxvf /root/redis-6.2.5.tar.gz -C ./
解压完之后,
/usr/local/redis
⽬录中会出现⼀个redis-6.2.5
的⽬录
二、编译安装
编译并安装
cd redis-6.2.5 make && make install
三、将redis服务安装系统服务并后台启动
进⼊
utils
⽬录,并执⾏下面命令cd utils/ ./install_server.sh
这步可能会报错
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 install_server.sh
76行 #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 #unset _pid_1_exe
查看redis服务启动情况
systemctl status redis_6379.service
看状态是不是
Active: active (running)
, 如果状态是Active: active (exited)
● redis_6379.service - LSB: start and stop redis_6379 Loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled) Active: active (exited) since 二 2021-09-14 16:46:05 CST; 8min ago Docs: man:systemd-sysv-generator(8) Process: 8528 ExecStart=/etc/rc.d/init.d/redis_6379 start (code=exited, status=0/SUCCESS) 9月 14 16:46:05 localhost.localdomain systemd[1]: Starting LSB: start and stop redis_6379... 9月 14 16:46:05 localhost.localdomain redis_6379[8528]: /var/run/redis_6379.pid exists, process is al...ed 9月 14 16:46:05 localhost.localdomain systemd[1]: Started LSB: start and stop redis_6379. Hint: Some lines were ellipsized, use -l to show in full.
Active: active (exited)
状态 删除pid文件cd /var/run rm redis_6379.pid
Active: active (exited)
状态 删除dump.rdb(内存快照)文件cd /var/lib/redis/6379 mv dump.rdb dump.rdb_bak
Active: active (exited)
状态ps -ef |grep redis kill -9 进程id(如果有) systemctl start redis
设置允许远程连接, 编辑
redis
配置⽂件vim /etc/redis/6379.conf
将
bind 127.0.0.1
修改为0.0.0.0
bind 0.0.0.0 systemctl restart redis_6379.service
设置访问密码
vim /etc/redis/6379.conf
找到
#requirepass foobared
去掉注释,修改foobared为⾃⼰想要的密码,保存即可。requirepass admin
保存,重启 Redis 服务即可
systemctl restart redis_6379.service
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。