服务器环境自动部署的脚本包括mysql,Elasticsearch, redis,nginx,jdk,nacos,RocketMq等
时间: 2023-09-11 16:07:49 浏览: 212
好的,以下是一个自动化部署脚本,可以安装和配置MySQL、Elasticsearch、Redis、Nginx、JDK、Nacos和RocketMQ等服务:
```bash
#!/bin/bash
# 定义服务器IP地址
server_ip="your_server_ip_address"
# 定义服务器用户名和密码
username="your_server_username"
password="your_server_password"
# 安装MySQL
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$username@$server_ip" << EOF
sudo apt-get update
sudo apt-get install -y mysql-server
sudo systemctl start mysql
sudo systemctl enable mysql
EOF
# 安装Elasticsearch
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$username@$server_ip" << EOF
sudo apt-get update
sudo apt-get install -y openjdk-8-jdk
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo apt-get install -y apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update
sudo apt-get install -y elasticsearch
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
EOF
# 安装Redis
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$username@$server_ip" << EOF
sudo apt-get update
sudo apt-get install -y redis-server
sudo systemctl start redis
sudo systemctl enable redis
EOF
# 安装Nginx
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$username@$server_ip" << EOF
sudo apt-get update
sudo apt-get install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
EOF
# 安装JDK
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$username@$server_ip" << EOF
sudo apt-get update
sudo apt-get install -y openjdk-8-jdk
EOF
# 安装Nacos
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$username@$server_ip" << EOF
wget https://github.com/alibaba/nacos/releases/download/1.4.1/nacos-server-1.4.1.tar.gz
tar -zxvf nacos-server-1.4.1.tar.gz
cd nacos/bin
sh startup.sh -m standalone
EOF
# 安装RocketMQ
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "$username@$server_ip" << EOF
wget https://www.apache.org/dist/rocketmq/4.9.1/rocketmq-all-4.9.1-bin-release.zip
unzip rocketmq-all-4.9.1-bin-release.zip
cd rocketmq-all-4.9.1-bin-release
sh bin/mqnamesrv &
sh bin/mqbroker -n localhost:9876 &
EOF
```
这个脚本的作用是自动登录到远程服务器,安装和配置MySQL、Elasticsearch、Redis、Nginx、JDK、Nacos和RocketMQ等服务。您需要将脚本中的变量替换为您自己的服务器信息,并确保安装了sshpass和所需的依赖。使用方法为在本地运行该脚本,然后等待部署完成即可。
阅读全文