我想创建一个bash脚本,它自动安装redis:
我的问题是更改两个文件中的行:
#Install Redis
sudo apt install redis-server
sudo nano /etc/redis/redis.conf我需要找到一行,默认情况下,changed.The有监督的指令被设置为no。
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous liveness pings back to your supervisor.
supervised systemd # this line to changesudo systemctl reload redis.servicesudo nano /etc/redis/redis.conf需要取消注释(如果存在#则删除#):bind 127.0.0.1 ::1
它也可以测试它吗?
redis-cli在下面的提示符中,使用ping命令测试连接:
ping
Output
PONG还是检查状态?
sudo systemctl status redis发布于 2018-08-13 17:05:45
是的,这是可能的,但你正在进行次优化。这是一个批处理过程,所以不要使用nano,使用文本处理工具。不要用sudo作为每个命令的前缀,而是将整个过程封装在一个脚本中,并使用sudo来执行脚本。
类似的东西(“类似的东西”,我的意思是“我没有尝试过,也没有安装redis-server。我认为这是我做了很多次的任务的另一个例子,但它应该能工作”):
#!/bin/bash
if [[ $(id -u) != 0 ]] ; then
echo "Must be run as root" >&2
exit 1
fi
apt update
apt install redis-server
# Just in case, ...
systemctl stop redis-server
# Change "supervised no" so "supervised systemd"? Question is unclear
# If "#bind 127.0.0.1 ::1", change to "bind 127.0.0.1 ::1"
sed -e '/^supervised no/supervised systemd/' \
-e 's/^# *bind 127\.0\.0\.1 ::1/bind 127.0.0.1 ::1' \
/etc/redis/redis.conf >/etc/redis/redis.conf.new
# $(date +%y%b%d-%H%M%S) == "18Aug13-125913"
mv /etc/redis/redis.conf /etc/redis/redis.conf.$(date +%y%b%d-%H%M%S)
mv /etc/redis/redis.conf.new /etc/redis/redis.conf
systemctl start redis-server
# give redis-server a second to wake up
sleep 1
if [[ "$( echo 'ping' | /usr/bin/redis-cli )" == "PONG" ]] ; then
echo "ping worked"
else
echo "ping FAILED"
fi
systemctl status redis
systemctl status redis-server
exit 0https://askubuntu.com/questions/1065018
复制相似问题