以下是一个CentOS下自动部署环境的脚本示例:

#!/bin/bash

# 更换yum源为本地挂载的iso源
mount /dev/cdrom /mnt
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
cat > /etc/yum.repos.d/CentOS-Base.repo << EOF
[BaseOS]
name=CentOS-\$releasever - Base
baseurl=file:///mnt/BaseOS/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[AppStream]
name=CentOS-\$releasever - AppStream
baseurl=file:///mnt/AppStream/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF

# 安装软件包
yum install -y redis keepalived nginx mysql scsi-target-utils

# 配置文件路径
redis_conf="/etc/redis.conf"
keepalive_conf="/etc/keepalived/keepalived.conf"
nginx_conf="/etc/nginx/nginx.conf"
mysql_conf="/etc/my.cnf"

# 替换配置文件
cp /path/to/redis.conf $redis_conf
cp /path/to/keepalived.conf $keepalive_conf
cp /path/to/nginx.conf $nginx_conf
cp /path/to/my.cnf $mysql_conf

# 启动服务
systemctl start redis
systemctl start keepalived
systemctl start nginx
systemctl start mysqld

注意替换脚本中的/path/to为你实际的配置文件路径。另外,这个脚本假设你已经将ISO镜像挂载到了/mnt目录下。如果你的挂载路径不同,请根据实际情况修改脚本。

保存脚本为deploy.sh,然后在终端上运行bash deploy.sh即可执行自动部署环境的操作

centos下写一个自动部署环境的脚本 包含先更换yum源为本地挂载的iso源 然后安装redis keepalive nginx mysql scsi 安装和指定配置文件

原文地址: http://www.cveoy.top/t/topic/h1l4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录