Shell script strategy (one-click deployment series) (Redis database)

Article Directory


1. Preparation

  • Download the software package portal : redis-5.0.7.tar.gz (extract code: qwer)
  • Transfer the downloaded software package to the /opt/ directory

2. Script content

The following is the script content:

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
#关闭防火墙及强制访问控制

yum -y install gcc gcc-c++ make
#下载依赖包

cd /opt
tar zxvf redis-5.0.7.tar.gz -C /opt/
#解压软件包

cd redis-5.0.7/
make -j 4
make PREFIX=/usr/local/redis install
#源码编译安装
#由于 Redis 源码包中直接提供了 Makefile 文件,所以在解压完软件包后,不用先执行./configure 进行配置

yum -y install tcl
yum -y install expect
#安装 Tcl 编程语言以支持免交互 expect

cd /opt/redis-5.0.7/utils/
/usr/bin/expect <<EOF
spawn ./install_server.sh
expect "instance" {send "\r"} 
expect "config" {send "\r"}
expect "log" {send "\r"}
expect "data" {send "\r"}
expect "executable" {send "/usr/local/redis/bin/redis-server\r"}
expect "abort" {send "\r"}
expect eof
EOF
#免交互
#执行软件包提供的 install_server.sh 脚本文件来设置 Redis 服务所需要的相关配置文件

ln -s /usr/local/redis/bin/* /usr/local/bin/
#把 redis 的可执行程序文件放入路径环境变量的目录中便于系统识别

sed -i '/bind 127.0.0.1/c bind 0.0.0.0' /etc/redis/6379.conf
sed -i 's/appendonly no/appendonly yes/' /etc/redis/6379.conf
#修改配置文件

/etc/init.d/redis_6379 restart
/etc/init.d/redis_6379 status
#重启 Redis,以使配置生效
#查看当前状态

netstat -natp | grep "redis"
#检查服务是否成功开启

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/114112331