redis啟動報錯Can‘t?open?the?log?file:?No?such?file?or?directory
問題描述
在使用docker-compose安裝redis的時候,啟動失敗,提示無法開發(fā)日志文件,這主要是容器中沒有對應的日志文件造成的,另一點就是對應的日志文件沒有相應權限所導致
異常信息如下所示
*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 103
>>> 'logfile /var/log/redis/redis.log'
Can't open the log file: No such file or directory
原因分析
這個提示里面的/var/log/redis/redis.log日志文件指的是容器中的文件,千萬別理解為宿主機中的路徑,如果你在宿主機創(chuàng)建此文件并授權,最后結果也是一樣的,理解這一點很重要。
相關docker-compse.yml
配置如下
version: '3' services: redis: hostname: redis image: redis:latest container_name: redis restart: unless-stopped command: redis-server /etc/redis.conf environment: - TZ=Asia/Shanghai # 時區(qū)設置 volumes: - /etc/localtime:/etc/localtime:ro # 時區(qū)設置 - ./data:/data # redis 數(shù)據(jù)存儲目錄 - ./redis.conf:/etc/redis.conf # redis配置文件 ports: - "6379:6379"
為了方面隨時修改redis配置,所以將配置文件進行了映射
redis中日志文件的配置項如下:
# Specify the log file name. Also the empty string can be used to force # Redis to log on the standard output. Note that if you use standard # output for logging but daemonize, logs will be sent to /dev/null logfile "/var/log/redis/redis.log"
啟動的時候就提示上述錯誤了,要解決這個問題有兩種方案
解決方案
方案一
直接將redis.conf中的logfile配置注釋掉或者設置為空就可以了,但是這樣就不會輸出日志了,如果有問題需要排查就不方面了。
方案二
在宿主機的./data目錄下創(chuàng)建redis.log文件并授予權限,當前redis安裝的絕對路徑為/home/local/docker/redis
以下都是指的相對路徑
touch data/redis.log chmod 777 data/redis.log 修改日志相關配置,這樣容器中就會自動創(chuàng)建日志文件并授予權限了 logfile "/data/redis.log" 重新構建并查看日志應該都正常了 docker-compose up --build -d docker logs redis
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Redis Redisson lock和tryLock的原理分析
這篇文章主要介紹了Redis Redisson lock和tryLock的原理分析,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-04-04