①准备两台设备,并安装Centos系统,设备名称简称:设备1和设备2
系统版本如下:
②准备一台Android设备,并开启USB调试
③准备一台操作电脑,并安装FinalShell工具
·········································································································································
注释:
#!/bin/bash
# 安装Docker
InstallDocker()
{
#1.安装依赖的软件包, yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2
#2.添加yum源,如该源无法使用可以使用阿里云Docker Yum源替代
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum makecache fast
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#3.安装docker
yum install -y docker-ce
#4.启动docker
systemctl start docker.service
#5.设置开机自启动
systemctl enable docker.service
#6.查看版本
docker version
if [ $? -eq 0 ]; then
echo "Docker安装成功"
else
echo "Docker安装失败,请检查配置是否有误"
exit 1
fi
}
#安装docker-compose
Installcompose()
{
#1.安装docker-compose github地址无法使用时可以选择国内http://get.daocloud.io/#install-compose网站上面的地址
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
#2.赋予权限
chmod +x /usr/local/bin/docker-compose
#3.查看版本
docker-compose -v
if [ $? -eq 0 ]; then
echo "docker-compose安装成功"
else
echo "docker-compose安装失败,请检查配置是否有误"
exit 1
fi
}
#安装mysql
InstallMysql()
{
mariadb=`rpm -qa | grep mariadb` #执行指令用反引号
if [ $mariadb ]; then
rpm -e $mariadb --nodeps
fi
yum -y install wget
yum -y install libaio
mkdir -p ./mysql
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar -O ./mysql/mysql.tar
cd mysql
tar -xvf mysql.tar
common=`find . -name "mysql-community-common*"`
libs=`find . -name "mysql-community-libs-8*"`
client=`find . -name "mysql-community-client*"`
server=`find . -name "mysql-community-server*"`
rpm -ivh $common
rpm -ivh $libs
rpm -ivh $client
rpm -ivh $server --force --nodeps
mysqld --initialize
chown mysql:mysql /var/lib/mysql -R
systemctl start mysqld.service
systemctl enable mysqld
cd ../
}
#安装Iptables
InstallIptables()
{
#关闭firewalld防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service
#安装iptables
yum -y install iptables-services
systemctl enable iptables
systemctl start iptables
#将匹配的行进行删除
iptables="/etc/sysconfig/iptables"
sed -i '/COMMIT/d' "$iptables"
sed -i '/--dport 80 -j/d' "$iptables"
sed -i '/--dport 3306/d' "$iptables"
sed -i '/--dport 443/d' "$iptables"
sed -i '/--dport 3000/d' "$iptables"
sed -i '/--dport 9090/d' "$iptables"
sed -i '/--dport 10389/d' "$iptables"
sed -i '/--dport 8094/d' "$iptables"
sed -i '/--dport 8095/d' "$iptables"
sed -i '/--dport 7777/d' "$iptables"
sed -i '/INPUT -j REJECT/d' "$iptables"
sed -i '/FORWARD -j REJECT/d' "$iptables"
#写入
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 10389 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 8094 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 8095 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 7777 -j ACCEPT">>$iptables
echo "-A INPUT -j REJECT --reject-with icmp-host-prohibited">>$iptables
echo "-A FORWARD -j REJECT --reject-with icmp-host-prohibited">>$iptables
echo "COMMIT">>$iptables
systemctl restart iptables.service
systemctl enable iptables.service
}
#配置MySQL数据库
Configure_mysql()
{
#库名
db="sonic"
#获取默认密码
initial_passwd=`cat /var/log/mysqld.log | grep password` #执行指令用反引号
obtain_passwd=${initial_passwd#*localhost: } #冒号后面有个空格,需要注意
#获取新密码,设置的默认密码为123abc,用户可自定义修改
new_passwd="123abc"
#连接数据库并修改密码
mysql -uroot -p$obtain_passwd --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$new_passwd';"
#设置远程连接
mysql -uroot -p$new_passwd --connect-expired-password -e "create user 'root'@'%' identified with mysql_native_password by '$new_passwd';grant all privileges on *.* to 'root'@'%' with grant option;ALTER USER 'root'@'localhost' IDENTIFIED BY '$new_passwd' PASSWORD EXPIRE NEVER;flush privileges;"
#新建数据库并导入库
mysql -uroot -p$new_passwd --connect-expired-password -e "create database $db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
}
#部署前后端
InstallServer()
{
#1.创建sonicserver文件夹
mkdir sonicserver
#2.进入sonicserver文件夹
cd sonicserver
#3.下载服务端包,新版本可去官网获取,https://github.com/SonicCloudOrg/sonic-server/releases
wget https://github.com/SonicCloudOrg/sonic-server/releases/download/v2.3.1/sonic-server-v2.3.1.zip
#4.解压文件
unzip sonic-server-v2.3.1.zip
#5.更改.env 中的信息,IP地址写服务器地址
ip="192.168.100.230"
#Service Config
sed -i "s/SONIC_SERVER_HOST=.*/SONIC_SERVER_HOST=$ip/" .env
sed -i "s/SONIC_EUREKA_USERNAME=.*/SONIC_EUREKA_USERNAME=sonic/" .env
sed -i "s/SONIC_EUREKA_PASSWORD=.*/SONIC_EUREKA_PASSWORD=sonicabc123/" .env
#MySQL Config
sed -i "s/MYSQL_HOST=.*/MYSQL_HOST=$ip/" .env
sed -i "s/MYSQL_PASSWORD=.*/MYSQL_PASSWORD=$new_passwd/" .env
#User Config
sed -i "s#LDAP_URL=.*#LDAP_URL=ldap://$ip:10389#" .env
#6.重启docker,保证服务正常
service docker restart
#7.部署
docker-compose up -d
}
# ping百度3次,检查网络连接是否正常
ping -c3 www.baidu.com
#shell脚本中$?是指上一次命令执行的成功或者失败的状态。如果成功就是0,失败为1
if [ $? -eq 0 ]; then
InstallDocker
Installcompose
InstallMysql
InstallIptables
Configure_mysql
InstallServer
else
echo "无法连接网络,请检查网络!"
exit 1
fi
·········································································································································
chmod 777 SonicServer.sh
./SonicServer.sh
脚本执行完成后,前后端部署就完成了(因 Eureka 心跳机制,刚启动完毕微服务间互相访问需要 3~5 分钟,请耐心等候)打开浏览器访问 http://ip/:3000)
·········································································································································
#!/bin/bash
# 安装JDK并配置环境变量,已知部分 JDK 出现不兼容的问题,Sonic 官方推荐使用 JDK15
Installjar()
{
#1.进入目录
cd /usr/local/
#2.下载JDK15
wget https://corretto.aws/downloads/latest/amazon-corretto-15-x64-linux-jdk.tar.gz
#3.解压文件
tar -zxvf amazon-corretto-15-x64-linux-jdk.tar.gz
#4.修改名称
mv amazon-corretto-15.0.2.7.1-linux-x64 java
#5.配置jdk环境变量
echo "" >> /etc/profile
echo "#JAVA_HOME" >> /etc/profile
echo "export JAVA_HOME=/usr/local/java" >> /etc/profile
echo "export PATH=\$JAVA_HOME/bin:\$PATH" >> /etc/profile
#6.source生效
source /etc/profile
#7.查看版本
java -version
if [ $? -eq 0 ]; then
echo "jdk安装成功"
else
echo "jdk安装失败,请检查配置是否有误"
exit 1
fi
}
# 安装node及npm环境配置
Installnode()
{
#1.下载node
wget https://cdn.npmmirror.com/binaries/node/v16.14.2/node-v16.14.2-linux-x64.tar.xz
#2.解压文件
tar -xvf node-v16.14.2-linux-x64.tar.xz
#3.修改名称
mv node-v16.14.2-linux-x64 node
#4.配置node环境变量,不知道为啥source /etc/profile在shell脚本中不行,需要手动执行,所以多加一个软链接
echo "" >> /etc/profile
echo "#node" >> /etc/profile
echo "export NODE_HOME=/usr/local/node/bin/" >> /etc/profile
echo "export PATH=\$NODE_HOME:\$PATH" >> /etc/profile
source /etc/profile
#创建软链接,以便可以在任意目录下使用 node 和 npm 命令
ln -s /usr/local/node/bin/node /usr/local/bin/node
ln -s /usr/local/node/bin/npm /usr/local/bin/npm
#5.source生效
source /etc/profile
#6.查看版本
node -v
if [ $? -eq 0 ]; then
echo "node安装成功"
else
echo "node安装失败,请检查配置是否有误"
exit 1
fi
npm -v
if [ $? -eq 0 ]; then
echo "npm安装成功"
else
echo "npm安装失败,请检查配置是否有误"
exit 1
fi
}
#Appium安装
InstallAppium()
{
#1.使用npm安装Appium
npm install -g appium
#2.source生效
source /etc/profile
#3.查看版本
appium -v
if [ $? -eq 0 ]; then
echo "appium安装成功"
else
echo "appium安装失败,请检查配置是否有误"
exit 1
fi
}
#adbkit安装
Installadbkit()
{
#1.使用npm安装adbkit
npm i -g adbkit
#2.source生效
source /etc/profile
#3.查看版本
adbkit -V
if [ $? -eq 0 ]; then
echo "adbkit安装成功"
else
echo "adbkit安装失败,请检查配置是否有误"
exit 1
fi
}
#下载SDK Tools的安装包并配置环境
InstallSdk()
{
#1.下载
wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
#2.解压文件
tar -zxvf android-sdk_r24.4.1-linux.tgz
#3.修改名称
mv android-sdk-linux android
#4.配置Sdk环境变量
echo "" >> /etc/profile
echo "#SDK_Tools" >> /etc/profile
echo "export ANDROID_HOME=/usr/local/android" >> /etc/profile
echo "export PATH=\$ANDROID_HOME/tools:\$PATH" >> /etc/profile
echo "export PATH=\$ANDROID_HOME/platform-tools:\$PATH" >> /etc/profile
#5.source生效
source /etc/profile
#6.安装sdk ,遇到询问直接y即可
android update sdk -u -a -t 1,2
#7.查看版本
adb version
if [ $? -eq 0 ]; then
echo "SDK_Tools安装成功"
else
echo "SDK_Tools安装失败,请检查配置是否有误"
exit 1
fi
}
#安装谷歌浏览器并配置
Installgoogle()
{
#1.下载谷歌浏览器
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
#2.安装谷歌浏览器
yum install -y google-chrome-stable_current_x86_64.rpm
#3.配置修改
sed -i '/exec -a "$0" "$HERE\/chrome" "$@"/d' "/opt/google/chrome/google-chrome"
echo 'exec -a "$0" "$HERE/chrome" "$@" –user-data-dir –no-sandbox' >> /opt/google/chrome/google-chrome
#4.chrome驱动安装,该部分需要手动执行
}
#下载Agent端
InstallAgent()
{
#1.下载
mkdir /home/sonicAgent
cd /home/sonicAgent
#加速链接,如果失效,请去官网下载新的包https://sonic-cloud.cn/deploy/agent-deploy.html
wget https://ghproxy.com/https://github.com/SonicCloudOrg/sonic-agent/releases/download/v2.3.1/sonic-agent-v2.3.1-linux_x86_64.zip
#2.解压文件
unzip sonic-agent-v2.3.1-linux_x86_64.zip
#3.配置文件修改,该部分需要手动执行
}
#关闭firewalld防火墙
firewalld()
{
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service
}
# ping百度3次,检查网络连接是否正常
ping -c3 www.baidu.com
#shell脚本中$?是指上一次命令执行的成功或者失败的状态。如果成功就是0,失败为1
if [ $? -eq 0 ]; then
Installjar
Installnode
InstallAppium
Installadbkit
InstallSdk
Installgoogle
InstallAgent
firewalld
else
echo "无法连接网络,请检查网络!"
exit 1
fi
chmod 777 SonicServer.sh
./SonicAgent.sh
/opt/google/chrome/chrome -version
vi /home/sonicAgent/config/application-sonic-agent.yml
cd /home/sonicAgent
java -Dfile.encoding=utf-8 -jar sonic-agent-xxxx.jar
Q1: Sonic Server设备重启,等待5分钟后,web端登录页面提示"系统出错了!“或"后台准备中…请稍后…”,该如何解决?
A1: 该问题是Sonic Server相关容器未启动,需要手动启动
docker ps -a
docker start 93cb3e7c2e30
Q2: 需要开放哪些端口?
A2: Sonic Server端:3306、3000、9090、10389、8094、8095 / Sonic Agent端:7777
Q3: Sonic Agent端离线?
A3: 检查服务是否有启动,如未启动,者启动服务(启动方法查看Sonic Agent配置)
Q4: Sonic Server端和Sonic Agent端是否可以部署到同一台设备上?
A4: 可以
Q5: Sonic Server端和Sonic Agent端是否必须在同一个局域网中?
A5: 不一定,也可以在不同局域网中,但前提Sonic Agent端必须能ping通Sonic Server端