我有一个环境变量MY_HOME,它有指向目录/home/abc的路径。
现在,我有一个redis.conf文件,在其中我需要像这样设置这个路径
**redis.conf**
pidfile $MY_HOME/local/var/pids/redis.pid
logfile $MY_HOME/local/var/log/redis.log
dir $MY_HOME/local/var/lib/redis/就像我们在命令行中所做的那样,这样我的配置文件就可以根据Environment变量选择路径。
发布于 2016-04-01 20:23:25
因为Redis可以从stdin读取它的配置,所以我做的事情非常类似@jolestar的建议。我在redis.conf中放置占位符变量,然后在Redis启动程序中使用sed替换它们。例如:
==========
$MY_HOME/redis/redis.conf
==========
...
pidfile {DIR}/pids/server{n}.pid
port 123{n}
...然后我有一个脚本来启动Redis:
==========
runredis.sh
==========
DIR=$MY_HOME/redis
for n in {1..4}; do
echo "starting redis-server #$n ..."
sed -e "s/{n}/$n/g" -e "s/{DIR}/$DIR/g" < $DIR/redis.conf | redis-server -
done我已经用了很久了,而且效果很好。
发布于 2019-03-24 22:55:22
这是Redis不支持的,但是使用envsubst (在几乎所有现代发行版上默认安装)在运行redis-server之前在环境变量的值中替代-to是可以实现的。
envsubst '$HOME:$MY_HOME' < ~/.tmpl_redis.conf > ~/.redis.conf && redis-server ~/.redis.conf
# or
envsubst '$MY_HOME' < ~/.tmpl_redis.conf > ~/.redis.conf && redis-server !#:5 # 5th argument from the previous command发布于 2014-09-09 14:00:25
我也找到了一个解决方案,但是redis配置不支持env。我想有两种方法:
https://stackoverflow.com/questions/19452637
复制相似问题