Linux环境下安装redis
文章目录
一、准备工作
- 下载
redis安装包, 放到root目录里面下载地址 在 /usr/local/ 下创建 redis ⽂件夹并进⼊
cd /usr/local/ mkdir redis cd redis将
redis安装包解压到/usr/local/redistar -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.sh76行 #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.pidActive: active (exited)状态 删除dump.rdb(内存快照)文件cd /var/lib/redis/6379 mv dump.rdb dump.rdb_bakActive: 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.0bind 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
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论