GDSM自动化部署shell脚本
从0部署
#!/bin/bash
#安装SDK
InstallSDK()
{
rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
yum -y update
yum -y install dotnet-sdk-2.1
ln -s ~/dotnet/dotnet /usr/local/bin
dotnet --version
mkdir /home/Documents
mv NETCore /home/Documents
chmod 777 /home/Documents/NETCore/wwwroot/Centos.sh
chmod 777 /home/Documents/NETCore/wwwroot/Date.sh
}
#安装mysql
InstallMysql()
{
mariadb=`rpm -qa | grep mariadb` #执行指令用反引号
if [ $mariadb ]; then
rpm -e $mariadb --nodeps
fi
yum -y install wget
#mkdir -p /root/Downloads
#cd /root/Downloads
#wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar -O /root/Downloads/mysql.tar
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
mysqld --initialize
chown mysql:mysql /var/lib/mysql -R
systemctl start mysqld.service
systemctl enable mysqld
}
#安装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 8080/d' "$iptables"
sed -i '/--dport 8090/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 8080 -j ACCEPT">>$iptables
echo "-A INPUT -m state --state NEW -m tcp -p tcp --dport 8090 -j ACCEPT">>$iptables
echo "COMMIT">>$iptables
systemctl restart iptables.service
systemctl enable iptables.service
}
#安装nginx
Installnginx()
{
yum -y install epel-release
yum -y install nginx
systemctl start nginx
systemctl enable nginx
\cp -f nginx.conf /etc/nginx/nginx.conf
\cp -f nx_netcore.conf /etc/nginx/conf.d
nginx -s reload
}
#安装supervisor
InstallSupervisor()
{
yum -y install python-setuptools
easy_install supervisor
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
echo "[include]">>/etc/supervisor/supervisord.conf
echo "files = /etc/supervisor/conf.d/*.conf">>/etc/supervisor/supervisord.conf
mkdir /etc/supervisor/conf.d
mkdir /etc/supervisor/log
\cp -f netcore.conf /etc/supervisor/conf.d
supervisord -c /etc/supervisor/supervisord.conf
\cp -f supervisord.service /usr/lib/systemd/system
systemctl enable supervisord.service
systemctl is-enabled supervisord
#将Nginx添加到SELinux白名单
yum -y install policycoreutils-python
semodule -i mynginx.pp
reboot
}
InstallSDK
InstallMysql
InstallIptables
Installnginx
InstallSupervisor
更新部署
#!/bin/bash
service supervisord stop
name=$1
mv /home/Documents/NETCore /home/Documents/NETCore1
mv /home/Documents/$name /home/Documents/NETCore
\cp -f /home/Documents/NETCore1/appsettings.json /home/Documents/NETCore
\cp -f /home/Documents/NETCore1/data.dll.config /home/Documents/NETCore
\mv -f /home/Documents/NETCore1/wwwroot/Content/userh5static/ /home/Documents/NETCore/wwwroot/Content/
\mv -f /home/Documents/NETCore1/wwwroot/Content/tempaltedown/ /home/Documents/NETCore/wwwroot/Content/
\mv -f /home/Documents/NETCore1/wwwroot/Content/userresource/ /home/Documents/NETCore/wwwroot/Content/
\mv -f /home/Documents/NETCore1/wwwroot/Content/resource/ /home/Documents/NETCore/wwwroot/Content/
service supervisord start