编写shell脚本:
cat install_redis.sh
#!/bin/bash
redis_config=/usr/local/redis/bin/redis.conf
function gcc_install(){
yum install gcc gcc-c++ man wget te.NET perl-devel Python/ target=_blank class=infotextkey>Python-devel net-tools -y
}
function install_redis () {
cd /usr/local/src
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
tar -zxf redis-6.2.6.tar.gz
cd redis-6.2.6 && make && make install PREFIX=/usr/local/redis
mkdir -p /usr/local/redis/{bin,run,log,data}
yes| cp -r /usr/local/src/redis-6.2.6/redis.conf /usr/local/redis/bin/
yes| cp -r /usr/local/src/redis-6.2.6/redis-server /usr/local/redis/bin/
sed -ri '/^daemonize/s/yes/no/' $redis_config
sed -ri '/^bind/s/127.0.0.1/0.0.0.0' $redis_config
sed -ri '/^dir/s/.///usr//local/redis/data/' $redis_config
sed -ri '/^protected-mode/s/yes/no/' $redis_config
sed -ri '/^logfile/s/""/"/usr//local/redis/log/redis.log"/' $redis_config
}
cat > /usr/lib/systemd/system/redis.service << EOF
[Unit]
After=network.target
[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf --supervised systemd
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
systemctl start redis.service
gcc_install
redis_install
如果您喜欢本文,就请动动您的发财手为本文点赞评论转发,让我们一起学习更多运维相关知识,最后请记得关注我。