本文主要是介绍在线编译安装redis脚本,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#!/bin/bash
INSTALL_DIR=/apps/redis
CONF_FILE=/apps/redis/etc/redis.conf
before_install (){
yum makecache && yum install -y gcc jemalloc > /dev/null
cd /usr/local/src && wget https://download.redis.io/releases/redis-5.0.9.tar.gz
tar xzvf redis-5.0.9.tar.gz > /dev/null
}
redis_install (){
cd redis-5.0.9 && make PREFIX=${INSTALL_DIR} install
}
after_install (){
useradd -r -s /sbin/nologin redis
mkdir -p /apps/redis/{etc,log,run,data} && chown redis.redis -R /apps/redis/
cp /usr/local/src/redis-5.0.9/redis.conf /apps/redis/etc/
sed -ri.bak '/^daemonize/s/yes/no/' $CONF_FILE
sed -ri '/^bind/s/127.0.0.1/0.0.0.0/' $CONF_FILE
sed -ri '/^protected-mode/s/yes/no/' $CONF_FILE
sed -ri '/^pidfile/s/\/var/\/apps\/redis/' $CONF_FILE
sed -ri '/^logfile/s/\"\"/\"\/apps\/redis\/log\/redis.log\"/' $CONF_FILE
sed -ri '/^dir/s/\.\//\/apps\/redis\/data/' $CONF_FILE
cat > /lib/systemd/system/redis.service << EOF
[Unit]
Description=Redis persistent key-value database
After=network.target
[Service]
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
#ExecStop=/usr/libexec/redis-shutdown
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
cat >> /etc/sysctl.conf << EOF
vm.overcommit_memory = 1
net.core.somaxconn = 1024
EOF
sysctl -p
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local && /etc/rc.d/rc.local
systemctl start redis && echo "redis 启动成功"
}
main (){
before_install
redis_install
after_install
}
main
这篇关于在线编译安装redis脚本的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!