• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

在线编译安装redis脚本

开发技术 开发技术 6小时前 2次浏览
#!/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脚本
喜欢 (0)