本文共 1260 字,大约阅读时间需要 4 分钟。
#!/usr/bin/env bash
set -eset -xREDISVERSION=4.0.1WORKSPACE=/tmpif [ $# -eq 1 ]; thenecho 'Redis version unspecified, use default: 4.0.1'REDISVERSION=$1fiapt-get updateapt-get install -y tcl build-essential#add redis user
groupadd redisuseradd redis -g redis -s /usr/sbin/nologin#workspace
mkdir -p /etc/redis /data/redis /var/log/redis#install
wget -O $WORKSPACE/redis-$REDISVERSION.tar.gztar xf $WORKSPACE/redis-$REDISVERSION.tar.gz -C $WORKSPACEcd $WORKSPACE/redis-$REDISVERSION && make && make test && make installcp $WORKSPACE/redis-$REDISVERSION/*.conf /etc/redis#configuration
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis/redis.confsed -i '/^logfile/c logfile "/var/log/redis/redis.log"' /etc/redis/redis.confsed -i '/^dir .\//c dir \/data\/redis\/' /etc/redis/redis.confcat << EOF > /lib/systemd/system/redis.service
[Unit]Description=Redis ServerAfter=network.target[Service]
User=redisGroup=redisExecStart=/usr/local/bin/redis-server /etc/redis/redis.confExecStop=/usr/local/bin/redis-cli -p 6379 shutdown[Install]
WantedBy=multi-user.targetEOF#startup
chown -R redis.redis /etc/redis /data/redis /var/log/redissystemctl daemon-reloadsystemctl enable redissystemctl start redis转载于:https://blog.51cto.com/jinliang/2107176