mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-09-28 12:24:50 +02:00
Submit aaPanel version 6.0.5
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
|
||||
OSNAME='CentOS'
|
||||
elif grep -Eqi "Red Hat Enterprise Linux Server" /etc/issue || grep -Eq "Red Hat Enterprise Linux Server" /etc/*-release; then
|
||||
OSNAME='RHEL'
|
||||
elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun" /etc/*-release; then
|
||||
OSNAME='Aliyun'
|
||||
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
|
||||
OSNAME='Fedora'
|
||||
elif grep -Eqi "Amazon Linux AMI" /etc/issue || grep -Eq "Amazon Linux AMI" /etc/*-release; then
|
||||
OSNAME='Amazon'
|
||||
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
|
||||
OSNAME='Debian'
|
||||
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
|
||||
OSNAME='Ubuntu'
|
||||
elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then
|
||||
OSNAME='Raspbian'
|
||||
elif grep -Eqi "Deepin" /etc/issue || grep -Eq "Deepin" /etc/*-release; then
|
||||
OSNAME='Deepin'
|
||||
else
|
||||
OSNAME='unknow'
|
||||
fi
|
||||
|
||||
echo "$OSNAME" > /www/server/panel/data/osname.pl
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
#备份网站
|
||||
Backup_Site()
|
||||
{
|
||||
#准备必要信息
|
||||
startTime=`date +%s`
|
||||
myDate=`date +"%Y%m%d_%H%M%S"`
|
||||
zipName=${1}_${myDate}.zip
|
||||
backupDir=${backup_path}/site
|
||||
fileName=$backupDir/$zipName
|
||||
tmp=`$Sql_Exec -e "SELECT id,path FROM bt_sites WHERE name='$1'"`;
|
||||
pid=`echo $tmp|awk '{print $3}'`
|
||||
sitePath=`echo $tmp|awk '{print $4}'`
|
||||
|
||||
if [ "$pid" == '' ];then
|
||||
endDate=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
log="网站[$1]不存在!"
|
||||
echo "★[$endDate] $log"
|
||||
echo '----------------------------------------------------------------------------'
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -d $backupDir ];then
|
||||
mkdir -p $backupDir
|
||||
fi
|
||||
|
||||
#取目录名称
|
||||
oldIFS=$IFS
|
||||
IFS=/
|
||||
nameArr=($sitePath)
|
||||
pathName=${nameArr[@]: -1};
|
||||
IFS=$oldIFS
|
||||
|
||||
#压缩
|
||||
cd $sitePath
|
||||
cd ..
|
||||
zip -r $fileName $pathName > /dev/null
|
||||
|
||||
if [ ! -f $fileName ];then
|
||||
endDate=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
log="网站[$1]备份失败!"
|
||||
echo "★[$endDate] $log"
|
||||
echo '----------------------------------------------------------------------------'
|
||||
exit
|
||||
fi
|
||||
|
||||
#记录日志
|
||||
endDate=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
endTime=`date +%s`
|
||||
((outTime=($endTime-$startTime)))
|
||||
|
||||
log="网站[$1]备份成功,用时[$outTime]秒"
|
||||
$Sql_Exec -e "INSERT INTO bt_backup(type,name,pid,filename,addtime) VALUES(0,'$zipName',$pid,'$fileName','$endDate')"
|
||||
$Sql_Exec -e "INSERT INTO bt_logs(type,log,addtime) VALUES('Cron','$log','$endDate')"
|
||||
echo "★[$endDate] $log"
|
||||
echo "|---保留最新的[$2]份备份"
|
||||
echo "|---文件名:$fileName"
|
||||
|
||||
#清理多余备份
|
||||
tmp=`$Sql_Exec -e "SELECT COUNT(*) FROM bt_backup WHERE type=0 AND pid=$pid"`;
|
||||
count=`echo $tmp|awk '{print $2}'`
|
||||
((sum=($count-$2)))
|
||||
if [ $sum -gt 0 ];then
|
||||
str=`$Sql_Exec -e "SELECT filename FROM bt_backup WHERE type=0 AND pid=$pid ORDER BY id ASC LIMIT $sum"`
|
||||
str=`echo $str|sed "s#filename##"|sed "s# ##"`
|
||||
oldIFS=$IFS
|
||||
IFS=' '
|
||||
arr=($str)
|
||||
for s in ${arr[@]}
|
||||
do
|
||||
if [ -f $s ];then
|
||||
rm -f $s
|
||||
fi
|
||||
echo "|---已清理过期备份文件:$s"
|
||||
$Sql_Exec -e "DELETE FROM bt_backup WHERE filename='$s'" > /dev/null
|
||||
done
|
||||
IFS=$oldIFS
|
||||
fi
|
||||
|
||||
echo '----------------------------------------------------------------------------'
|
||||
}
|
||||
|
||||
#备份数据库
|
||||
Backup_Database()
|
||||
{
|
||||
#准备必要信息
|
||||
startTime=`date +%s`
|
||||
mysqlRoot=`echo $select |grep mysql_root|awk '{print $3}'`
|
||||
myDate=`date +"%Y%m%d_%H%M%S"`
|
||||
sqlName=${1}_${myDate}.sql
|
||||
zipName=${1}_${myDate}.zip
|
||||
backupDir=${backup_path}/database
|
||||
tmp=`$Sql_Exec -e "SELECT id FROM bt_databases WHERE name='$1'"`;
|
||||
pid=`echo $tmp|awk '{print $2}'`
|
||||
|
||||
if [ "$pid" == '' ];then
|
||||
endDate=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
log="数据库[$1]不存在!"
|
||||
echo "★[$endDate] $log"
|
||||
echo '----------------------------------------------------------------------------'
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -d $backupDir ];then
|
||||
mkdir -p $backupDir
|
||||
fi
|
||||
|
||||
|
||||
#sed -i "s###"
|
||||
isWrite=`cat /etc/my.cnf|grep 'user=root'`
|
||||
if [ "${isWrite}" == '' ];then
|
||||
echo -e "\n[mysqldump]\nuser=root\npassword=$mysqlRoot" >> /etc/my.cnf
|
||||
else
|
||||
sed -i "s#password=.*#password=$mysqlRoot#" /etc/my.cnf
|
||||
fi
|
||||
|
||||
#导出数据库
|
||||
cd $backupDir
|
||||
/www/server/mysql/bin/mysqldump -uroot -p$mysqlRoot -R $1 > $sqlName
|
||||
|
||||
sed -i "/\[mysqldump\]/d" /etc/my.cnf
|
||||
sed -i "/user=root/d" /etc/my.cnf
|
||||
sed -i "/password=.*/d" /etc/my.cnf
|
||||
sed -i "s/quick/\[mysqldump\]\nquick/" /etc/my.cnf
|
||||
|
||||
|
||||
if [ ! -f $sqlName ];then
|
||||
endDate=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
log="数据库[$1]备份失败!"
|
||||
echo "★[$endDate] $log"
|
||||
echo '----------------------------------------------------------------------------'
|
||||
exit
|
||||
fi
|
||||
|
||||
#压缩
|
||||
zip -r $zipName $sqlName > /dev/null
|
||||
rm -f $sqlName
|
||||
|
||||
#记录日志
|
||||
endDate=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
endTime=`date +%s`
|
||||
((outTime=($endTime-$startTime)))
|
||||
fileName=$backupDir/$zipName
|
||||
log="数据库[$1]备份成功,用时[$outTime]秒"
|
||||
$Sql_Exec -e "INSERT INTO bt_backup(type,name,pid,filename,addtime) VALUES(1,'$zipName',$pid,'$fileName','$endDate')" > /dev/null
|
||||
$Sql_Exec -e "INSERT INTO bt_logs(type,log,addtime) VALUES('Cron','$log','$endDate')" > /dev/null
|
||||
echo "★[$endDate] $log"
|
||||
echo "|---保留最新的[$2]份备份"
|
||||
echo "|---文件名:$fileName"
|
||||
|
||||
#清理多余备份
|
||||
tmp=`$Sql_Exec -e "SELECT COUNT(*) FROM bt_backup WHERE type=1 AND pid=$pid"`;
|
||||
count=`echo $tmp|awk '{print $2}'`
|
||||
((sum=($count-$2)))
|
||||
if [ $sum -gt 0 ];then
|
||||
str=`$Sql_Exec -e "SELECT filename FROM bt_backup WHERE type=1 AND pid=$pid ORDER BY id ASC LIMIT $sum"`
|
||||
str=`echo $str|sed "s#filename##"|sed "s# ##"`
|
||||
oldIFS=$IFS
|
||||
IFS=' '
|
||||
arr=($str)
|
||||
for s in ${arr[@]}
|
||||
do
|
||||
if [ -f $s ];then
|
||||
rm -f $s
|
||||
fi
|
||||
echo "|---已清理过期备份文件:$s"
|
||||
$Sql_Exec -e "DELETE FROM bt_backup WHERE filename='$s'" > /dev/null
|
||||
done
|
||||
IFS=$oldIFS
|
||||
fi
|
||||
echo '----------------------------------------------------------------------------'
|
||||
}
|
||||
|
||||
|
||||
#准备基础信息
|
||||
action=$1
|
||||
name=$2
|
||||
num=$3
|
||||
dbPwd=`cat /www/wwwroot/default/conf/sql.config.php |grep 'DB_PWD'|awk '{print $3}'|sed "s#'##g"|sed "s#,##g"`
|
||||
dbName='bt_default'
|
||||
Sql_Exec="/www/server/mysql/bin/mysql -u$dbName -p$dbPwd --default-character-set=utf8 -D $dbName"
|
||||
select=`$Sql_Exec -e "SELECT mysql_root,backup_path FROM bt_config WHERE id=1"`
|
||||
backup_path=`echo $select |grep backup_path|awk '{print $4}'`
|
||||
|
||||
case "${action}" in
|
||||
'site')
|
||||
Backup_Site $name $num
|
||||
;;
|
||||
'database')
|
||||
Backup_Database $name $num
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,195 @@
|
||||
#!/usr/bin/python
|
||||
#coding: utf-8
|
||||
#-----------------------------
|
||||
# 宝塔Linux面板网站备份工具
|
||||
#-----------------------------
|
||||
|
||||
import sys,os
|
||||
os.chdir('/www/server/panel');
|
||||
sys.path.append("class/")
|
||||
if sys.version_info[0] == 2:
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
import public,db,time
|
||||
|
||||
class backupTools:
|
||||
|
||||
def backupSite(self,name,count):
|
||||
sql = db.Sql();
|
||||
path = sql.table('sites').where('name=?',(name,)).getField('path');
|
||||
startTime = time.time();
|
||||
if not path:
|
||||
endDate = time.strftime('%Y/%m/%d %X',time.localtime())
|
||||
log = public.GetMsg("SITE_NOT_EXIST1",(name,))
|
||||
print(u"★["+endDate+"] "+log)
|
||||
print("----------------------------------------------------------------------------")
|
||||
return;
|
||||
|
||||
backup_path = sql.table('config').where("id=?",(1,)).getField('backup_path') + '/site';
|
||||
if not os.path.exists(backup_path): public.ExecShell("mkdir -p " + backup_path);
|
||||
|
||||
filename= backup_path + "/Web_" + name + "_" + time.strftime('%Y%m%d_%H%M%S',time.localtime()) + '.tar.gz'
|
||||
public.ExecShell("cd " + os.path.dirname(path) + " && tar zcvf '" + filename + "' '" + os.path.basename(path) + "' > /dev/null")
|
||||
|
||||
|
||||
endDate = time.strftime('%Y/%m/%d %X',time.localtime())
|
||||
|
||||
if not os.path.exists(filename):
|
||||
log = public.GetMsg("SITE_BACK_FILE",(name,))
|
||||
print(u"★["+endDate+"] "+log)
|
||||
print(u"----------------------------------------------------------------------------")
|
||||
return;
|
||||
|
||||
outTime = time.time() - startTime
|
||||
pid = sql.table('sites').where('name=?',(name,)).getField('id');
|
||||
sql.table('backup').add('type,name,pid,filename,addtime,size',('0',os.path.basename(filename),pid,filename,endDate,os.path.getsize(filename)))
|
||||
log = public.GetMsg("SITE_BACKFTP_SUCCESS",(name,str(round(outTime,2))))
|
||||
public.WriteLog('TYPE_CRON',log)
|
||||
print(u"★["+endDate+"] " + log)
|
||||
print(public.GetMsg("KEEP_PART",(count,)))
|
||||
print(public.GetMsg("FTP_FILE_NAME")+filename)
|
||||
|
||||
#清理多余备份
|
||||
backups = sql.table('backup').where('type=? and pid=? and filename!=? and filename!=? and filename!=? and filename!=? and filename!=?',('0',pid,'alioss','txcos','upyun','qiniu','ftp')).field('id,filename').select();
|
||||
|
||||
num = len(backups) - int(count)
|
||||
if num > 0:
|
||||
for backup in backups:
|
||||
public.ExecShell("rm -f " + backup['filename']);
|
||||
sql.table('backup').where('id=?',(backup['id'],)).delete();
|
||||
num -= 1;
|
||||
print(public.GetMsg("FTP_CLEAN_BACK_FILE") + backup['filename'])
|
||||
if num < 1: break;
|
||||
|
||||
def backupDatabase(self,name,count):
|
||||
sql = db.Sql();
|
||||
path = sql.table('databases').where('name=?',(name,)).getField('id');
|
||||
startTime = time.time();
|
||||
if not path:
|
||||
endDate = time.strftime('%Y/%m/%d %X',time.localtime())
|
||||
log = public.GetMsg("FTP_DB_NOT_EXIST",(name,))
|
||||
print(u"★["+endDate+"] "+log)
|
||||
print(u"----------------------------------------------------------------------------")
|
||||
return;
|
||||
|
||||
backup_path = sql.table('config').where("id=?",(1,)).getField('backup_path') + '/database';
|
||||
if not os.path.exists(backup_path): public.ExecShell("mkdir -p " + backup_path);
|
||||
|
||||
filename = backup_path + "/Db_" + name + "_" + time.strftime('%Y%m%d_%H%M%S',time.localtime())+".sql.gz"
|
||||
|
||||
import re
|
||||
mysql_root = sql.table('config').where("id=?",(1,)).getField('mysql_root')
|
||||
|
||||
mycnf = public.readFile('/etc/my.cnf');
|
||||
rep = "\[mysqldump\]\nuser=root"
|
||||
sea = "[mysqldump]\n"
|
||||
subStr = sea + "user=root\npassword=" + mysql_root+"\n";
|
||||
mycnf = mycnf.replace(sea,subStr)
|
||||
if len(mycnf) > 100:
|
||||
public.writeFile('/etc/my.cnf',mycnf);
|
||||
|
||||
public.ExecShell("/www/server/mysql/bin/mysqldump --force --opt " + name + " | gzip > " + filename)
|
||||
|
||||
if not os.path.exists(filename):
|
||||
endDate = time.strftime('%Y/%m/%d %X',time.localtime())
|
||||
log = public.GetMsg("FTP_DB_BACK",(name,))
|
||||
print(u"★["+endDate+"] "+log)
|
||||
print(u"----------------------------------------------------------------------------")
|
||||
return;
|
||||
|
||||
mycnf = public.readFile('/etc/my.cnf');
|
||||
mycnf = mycnf.replace(subStr,sea)
|
||||
if len(mycnf) > 100:
|
||||
public.writeFile('/etc/my.cnf',mycnf);
|
||||
|
||||
endDate = time.strftime('%Y/%m/%d %X',time.localtime())
|
||||
outTime = time.time() - startTime
|
||||
pid = sql.table('databases').where('name=?',(name,)).getField('id');
|
||||
|
||||
sql.table('backup').add('type,name,pid,filename,addtime,size',(1,os.path.basename(filename),pid,filename,endDate,os.path.getsize(filename)))
|
||||
log = public.GetMsg("FTP_DB_BACK_SUCCESS",(name,str(round(outTime,2))))
|
||||
public.WriteLog('TYPE_CRON',log)
|
||||
print("★["+endDate+"] " + log)
|
||||
print(public.GetMsg("KEEP_PART",(count,)))
|
||||
print(public.GetMsg("FTP_FILE_NAME")+filename)
|
||||
|
||||
#清理多余备份
|
||||
backups = sql.table('backup').where('type=? and pid=? and filename!=? and filename!=? and filename!=? and filename!=? and filename!=?',('1',pid,'alioss','txcos','upyun','qiniu','ftp')).field('id,filename').select();
|
||||
|
||||
num = len(backups) - int(count)
|
||||
if num > 0:
|
||||
for backup in backups:
|
||||
public.ExecShell("rm -f " + backup['filename']);
|
||||
sql.table('backup').where('id=?',(backup['id'],)).delete();
|
||||
num -= 1;
|
||||
print(public.GetMsg("FTP_CLEAN_BACK_FILE") + backup['filename'])
|
||||
if num < 1: break;
|
||||
|
||||
#备份指定目录
|
||||
def backupPath(self,path,count):
|
||||
sql = db.Sql();
|
||||
startTime = time.time();
|
||||
if path[-1:] == '/': path = path[:-1]
|
||||
name = os.path.basename(path)
|
||||
backup_path = sql.table('config').where("id=?",(1,)).getField('backup_path') + '/path';
|
||||
if not os.path.exists(backup_path): os.makedirs(backup_path);
|
||||
filename= backup_path + "/Path_" + name + "_" + time.strftime('%Y%m%d_%H%M%S',time.localtime()) + '.tar.gz'
|
||||
os.system("cd " + os.path.dirname(path) + " && tar zcvf '" + filename + "' '" + os.path.basename(path) + "' > /dev/null")
|
||||
|
||||
endDate = time.strftime('%Y/%m/%d %X',time.localtime())
|
||||
if not os.path.exists(filename):
|
||||
log = public.GetMsg("FTP_DIR_BACK_FAIL",(path,))
|
||||
print(u"★["+endDate+"] "+log)
|
||||
print(u"----------------------------------------------------------------------------")
|
||||
return;
|
||||
|
||||
outTime = time.time() - startTime
|
||||
sql.table('backup').add('type,name,pid,filename,addtime,size',('2',path,'0',filename,endDate,os.path.getsize(filename)))
|
||||
log = public.GetMsg("FTP_DIR_BACK_SUCCESS",(path,str(round(outTime,2))))
|
||||
public.WriteLog('TYPE_CRON',log)
|
||||
print(u"★["+endDate+"] " + log)
|
||||
print(public.GetMsg("KEEP_PART",(count,)))
|
||||
print(public.GetMsg("FTP_FILE_NAME")+filename)
|
||||
|
||||
#清理多余备份
|
||||
backups = sql.table('backup').where('type=? and pid=? and name=?',('2',0,path)).field('id,filename').select();
|
||||
num = len(backups) - int(count)
|
||||
if num > 0:
|
||||
for backup in backups:
|
||||
public.ExecShell("rm -f " + backup['filename']);
|
||||
sql.table('backup').where('id=?',(backup['id'],)).delete();
|
||||
num -= 1;
|
||||
print(public.GetMsg("FTP_CLEAN_BACK_FILE") + backup['filename'])
|
||||
if num < 1: break;
|
||||
|
||||
|
||||
def backupSiteAll(self,save):
|
||||
sites = public.M('sites').field('name').select()
|
||||
for site in sites:
|
||||
self.backupSite(site['name'],save)
|
||||
|
||||
|
||||
def backupDatabaseAll(self,save):
|
||||
databases = public.M('databases').field('name').select()
|
||||
for database in databases:
|
||||
self.backupDatabase(database['name'],save)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
backup = backupTools()
|
||||
type = sys.argv[1];
|
||||
if type == 'site':
|
||||
if sys.argv[2] == 'ALL':
|
||||
backup.backupSiteAll( sys.argv[3])
|
||||
else:
|
||||
backup.backupSite(sys.argv[2], sys.argv[3])
|
||||
elif type == 'path':
|
||||
backup.backupPath(sys.argv[2],sys.argv[3])
|
||||
elif type == 'database':
|
||||
if sys.argv[2] == 'ALL':
|
||||
backup.backupDatabaseAll(sys.argv[3])
|
||||
else:
|
||||
backup.backupDatabase(sys.argv[2], sys.argv[3])
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
install_tmp='/tmp/bt_install.pl'
|
||||
download_Url=http://download.bt.cn
|
||||
Install_Ftp()
|
||||
{
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
wget -O /www/server/panel/script/backup_ftp.py $download_Url/install/lib/script/backup_ftp.py -T 5
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_Ftp()
|
||||
{
|
||||
rm -f /www/server/panel/script/backup_ftp.py
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_Ftp
|
||||
else
|
||||
Uninstall_Ftp
|
||||
fi
|
||||
@@ -0,0 +1,235 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
echo "
|
||||
+----------------------------------------------------------------------
|
||||
| Bt-WebPanel 3.0 FOR CentOS beta
|
||||
+----------------------------------------------------------------------
|
||||
| Copyright (c) 2015-2017 BT-SOFT(http://www.bt.cn) All rights reserved.
|
||||
+----------------------------------------------------------------------
|
||||
| Python2.6/2.7 successful the http://SERVER_IP:8888 is WebPanel
|
||||
+----------------------------------------------------------------------
|
||||
"
|
||||
|
||||
download_Url='http://download.bt.cn'
|
||||
setup_patn=/www
|
||||
|
||||
while [ "$go" != 'y' ] && [ "$go" != 'n' ]
|
||||
do
|
||||
read -p "Now do you want to install Bt-Panel to the $setup_patn directory?(y/n): " go;
|
||||
done
|
||||
|
||||
if [ "$go" == 'n' ];then
|
||||
exit;
|
||||
fi
|
||||
|
||||
yum -y install ntp
|
||||
\cp -a -r /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
echo 'Synchronizing system time..'
|
||||
ntpdate 0.asia.pool.ntp.org
|
||||
hwclock -w
|
||||
|
||||
startTime=`date +%s`
|
||||
|
||||
rm -f /var/run/yum.pid
|
||||
paces="wget python-devel python-imaging zip unzip openssl openssl-devel gcc libxml2 libxml2-dev libxslt* zlib zlib-devel libjpeg-devel libpng-devel libwebp libwebp-devel freetype freetype-devel lsof pcre pcre-devel vixie-cron crontabs"
|
||||
yum -y install $paces
|
||||
|
||||
if [ ! -f '/usr/bin/mysql_config' ];then
|
||||
yum install mysql-devel -y
|
||||
fi
|
||||
|
||||
tmp=`python -V 2>&1|awk '{print $2}'`
|
||||
pVersion=${tmp:0:3}
|
||||
|
||||
if [ ! -f "/usr/lib/python${pVersion}/site-packages/setuptools-33.1.1-py${pVersion}.egg" ];then
|
||||
wget $download_Url/install/src/setuptools-33.1.1.zip -T 10
|
||||
unzip setuptools-33.1.1.zip
|
||||
rm -f setuptools-33.1.1.zip
|
||||
cd setuptools-33.1.1
|
||||
python setup.py install
|
||||
cd ..
|
||||
rm -rf setuptools-33.1.1
|
||||
fi
|
||||
|
||||
if [ ! -f "/usr/lib64/python${pVersion}/site-packages/Pillow-3.2.0-py${pVersion}-linux-x86_64.egg" ] && [ ! -f "/usr/lib/python${pVersion}/site-packages/Pillow-3.2.0-py${pVersion}-linux-x86_64.egg" ];then
|
||||
wget $download_Url/install/src/Pillow-3.2.0.zip -T 10
|
||||
unzip Pillow-3.2.0.zip
|
||||
rm -f Pillow-3.2.0.zip
|
||||
cd Pillow-3.2.0
|
||||
python setup.py install
|
||||
cd ..
|
||||
rm -rf Pillow-3.2.0
|
||||
fi
|
||||
|
||||
if [ ! -d "/usr/lib/python${pVersion}/site-packages/psutil-5.1.3-py${pVersion}-linux-x86_64.egg" ] && [ ! -d "/usr/lib64/python${pVersion}/site-packages/psutil-5.1.3-py${pVersion}-linux-x86_64.egg" ];then
|
||||
wget $download_Url/install/src/psutil-5.1.3.tar.gz -T 10
|
||||
tar xvf psutil-5.1.3.tar.gz
|
||||
rm -f psutil-5.1.3.tar.gz
|
||||
cd psutil-5.1.3
|
||||
python setup.py install
|
||||
cd ..
|
||||
rm -rf psutil-5.1.3
|
||||
fi
|
||||
|
||||
if [ ! -f "/usr/lib64/python${pVersion}/site-packages/MySQL_python-1.2.5-py${pVersion}-linux-x86_64.egg" ] && [ ! -f "/usr/lib/python${pVersion}/site-packages/MySQL_python-1.2.5-py${pVersion}-linux-x86_64.egg" ];then
|
||||
wget $download_Url/install/src/MySQL-python-1.2.5.zip -T 10
|
||||
unzip MySQL-python-1.2.5.zip
|
||||
rm -f MySQL-python-1.2.5.zip
|
||||
cd MySQL-python-1.2.5
|
||||
python setup.py install
|
||||
cd ..
|
||||
rm -rf MySQL-python-1.2.5
|
||||
fi
|
||||
|
||||
if [ ! -f "/usr/lib/python${pVersion}/site-packages/chardet-2.3.0-py${pVersion}.egg" ];then
|
||||
wget $download_Url/install/src/chardet-2.3.0.tar.gz -T 10
|
||||
tar xvf chardet-2.3.0.tar.gz
|
||||
rm -f chardet-2.3.0.tar.gz
|
||||
cd chardet-2.3.0
|
||||
python setup.py install
|
||||
cd ..
|
||||
rm -rf chardet-2.3.0
|
||||
fi
|
||||
if [ ! -f "/usr/lib/python${pVersion}/site-packages/web.py-0.38-py${pVersion}.egg-info" ];then
|
||||
wget $download_Url/install/src/web.py-0.38.tar.gz -T 10
|
||||
tar xvf web.py-0.38.tar.gz
|
||||
rm -f web.py-0.38.tar.gz
|
||||
cd web.py-0.38
|
||||
python setup.py install
|
||||
cd ..
|
||||
rm -rf web.py-0.38
|
||||
fi
|
||||
|
||||
|
||||
mkdir -p $setup_patn/server/panel/logs
|
||||
wget https://dl.eff.org/certbot-auto --no-check-certificate -O $setup_patn/server/panel/certbot-auto
|
||||
chmod +x $setup_patn/server/panel/certbot-auto
|
||||
isCron=`cat /var/spool/cron/root|grep certbot.log`
|
||||
if [ "${isCron}" == "" ];then
|
||||
echo "30 2 * * * $setup_patn/server/panel/certbot-auto renew >> $setup_patn/server/panel/logs/certbot.log" >> /var/spool/cron/root
|
||||
chown 600 /var/spool/cron/root
|
||||
fi
|
||||
|
||||
if [ -f '/etc/init.d/bt' ];then
|
||||
service bt stop
|
||||
fi
|
||||
|
||||
mkdir -p /www/server
|
||||
mkdir -p /www/wwwroot
|
||||
mkdir -p /www/wwwlogs
|
||||
mkdir -p /www/backup/database
|
||||
mkdir -p /www/backup/site
|
||||
|
||||
|
||||
wget -O panel.zip $download_Url/install/src/panel.zip -T 10
|
||||
wget -O /etc/init.d/bt $download_Url/install/src/bt.init -T 10
|
||||
if [ -f "$setup_patn/server/panel/data/default.db" ];then
|
||||
if [ -d "/$setup_patn/server/panel/old_data" ];then
|
||||
rm -rf /$setup_patn/server/panel/old_data
|
||||
fi
|
||||
mv $setup_patn/server/panel/data /$setup_patn/server/panel/old_data
|
||||
fi
|
||||
|
||||
unzip -o panel.zip -d $setup_patn/server/ > /dev/null
|
||||
|
||||
if [ -d "$setup_patn/server/panel/old_data" ];then
|
||||
if [ -d "/$setup_patn/server/panel/data" ];then
|
||||
rm -rf /$setup_patn/server/panel/data
|
||||
fi
|
||||
mv /$setup_patn/server/panel/old_data $setup_patn/server/panel/data
|
||||
fi
|
||||
|
||||
|
||||
rm -f panel.zip
|
||||
|
||||
rm -f $setup_patn/server/panel/class/*.pyc
|
||||
rm -f $setup_patn/server/panel/*.pyc
|
||||
python -m compileall $setup_patn/server/panel
|
||||
rm -f $setup_patn/server/panel/class/*.py
|
||||
rm -f $setup_patn/server/panel/*.py
|
||||
|
||||
chmod +x /etc/init.d/bt
|
||||
chkconfig --add bt
|
||||
chkconfig --level 2345 bt on
|
||||
echo '8888' > $setup_patn/server/panel/data/port.pl
|
||||
chmod -R 600 $setup_patn/server/panel
|
||||
chmod +x $setup_patn/server/panel/certbot-auto
|
||||
chmod -R +x $setup_patn/server/panel/script
|
||||
service bt start
|
||||
password=`cat /dev/urandom | head -n 16 | md5sum | head -c 8`
|
||||
cd $setup_patn/server/panel/
|
||||
python tools.pyc panel $password
|
||||
cd ~
|
||||
echo "$password" > $setup_patn/server/panel/default.pl
|
||||
chmod 600 $setup_patn/server/panel/default.pl
|
||||
|
||||
if [ -f "/etc/init.d/iptables" ];then
|
||||
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
|
||||
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
|
||||
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
|
||||
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
|
||||
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8888 -j ACCEPT
|
||||
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 30000:40000 -j ACCEPT
|
||||
service iptables save
|
||||
|
||||
iptables_status=`service iptables status | grep 'not running'`
|
||||
if [ "${iptables_status}" == '' ];then
|
||||
service iptables restart
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${isVersion}" == '' ];then
|
||||
if [ ! -f "/etc/init.d/iptables" ];then
|
||||
yum install firewalld -y
|
||||
systemctl enable firewalld
|
||||
systemctl start firewalld
|
||||
firewall-cmd --permanent --zone=public --add-port=20/tcp
|
||||
firewall-cmd --permanent --zone=public --add-port=21/tcp
|
||||
firewall-cmd --permanent --zone=public --add-port=22/tcp
|
||||
firewall-cmd --permanent --zone=public --add-port=80/tcp
|
||||
firewall-cmd --permanent --zone=public --add-port=8888/tcp
|
||||
firewall-cmd --permanent --zone=public --add-port=30000-40000/tcp
|
||||
firewall-cmd --reload
|
||||
fi
|
||||
fi
|
||||
|
||||
yum -y install epel-release
|
||||
country=`curl -sS --connect-timeout 10 -m 60 http://ip.vpser.net/country`
|
||||
if [ "${country}" = "CN" ]; then
|
||||
mkdir ~/.pip
|
||||
cat > ~/.pip/pip.conf <<EOF
|
||||
[global]
|
||||
index-url = https://pypi.doubanio.com/simple/
|
||||
|
||||
[install]
|
||||
trusted-host=pypi.doubanio.com
|
||||
EOF
|
||||
fi
|
||||
nohup $setup_patn/server/panel/certbot-auto -n > /tmp/certbot-auto.log 2>&1 &
|
||||
|
||||
address=""
|
||||
n=0
|
||||
while [ "$address" == '' ]
|
||||
do
|
||||
address=`curl -s http://city.ip138.com/ip2city.asp|grep -Eo '([0-9]+\.){3}[0-9]+'`
|
||||
let n++
|
||||
sleep 0.1
|
||||
if [ $n -gt 5 ];then
|
||||
address="SERVER_IP"
|
||||
fi
|
||||
done
|
||||
|
||||
curl http://www.bt.cn/Api/SetupCount?type=Linux
|
||||
|
||||
echo "====================================="
|
||||
echo -e "\033[32mThe install successful!\033[0m"
|
||||
echo -e "====================================="
|
||||
echo -e "Bt-Panel: http://$address:8888"
|
||||
echo -e "username: admin"
|
||||
echo -e "password: $password"
|
||||
echo -e "====================================="
|
||||
endTime=`date +%s`
|
||||
((outTime=($endTime-$startTime)/60))
|
||||
echo -e "Time consuming:\033[32m $outTime \033[0mMinute!"
|
||||
rm -f install.sh
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/python
|
||||
#coding: utf-8
|
||||
#-----------------------------
|
||||
#宝塔Linux面板网站日志切割脚本
|
||||
#-----------------------------
|
||||
import sys
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
import glob
|
||||
os.chdir("/www/server/panel")
|
||||
sys.path.append('class/')
|
||||
import public
|
||||
print ('==================================================================')
|
||||
print( '★['+time.strftime("%Y/%m/%d %H:%M:%S")+'],切割日志')
|
||||
print ('==================================================================')
|
||||
print ('|--当前保留最新的['+sys.argv[2]+']份')
|
||||
logsPath = '/www/wwwlogs/'
|
||||
is_nginx = False
|
||||
if os.path.exists('/www/server/nginx/logs/nginx.pid'): is_nginx = True
|
||||
px = '.log'
|
||||
if not is_nginx: px = '-access_log'
|
||||
|
||||
def split_logs(oldFileName,num):
|
||||
global logsPath
|
||||
if not os.path.exists(oldFileName):
|
||||
print('|---'+oldFileName+'文件不存在!')
|
||||
return
|
||||
|
||||
logs=sorted(glob.glob(oldFileName+"_*"))
|
||||
count=len(logs)
|
||||
num=count - num
|
||||
|
||||
for i in range(count):
|
||||
if i>num: break;
|
||||
os.remove(logs[i])
|
||||
print('|---多余日志['+logs[i]+']已删除!')
|
||||
|
||||
newFileName=oldFileName+'_'+time.strftime("%Y-%m-%d_%H%M%S")+'.log'
|
||||
shutil.move(oldFileName,newFileName)
|
||||
print('|---已切割日志到:'+newFileName)
|
||||
|
||||
def split_all(save):
|
||||
sites = public.M('sites').field('name').select()
|
||||
for site in sites:
|
||||
oldFileName = logsPath + site['name'] + px
|
||||
split_logs(oldFileName,save)
|
||||
|
||||
if __name__ == '__main__':
|
||||
num = int(sys.argv[2])
|
||||
if sys.argv[1].find('ALL') == 0:
|
||||
split_all(num)
|
||||
else:
|
||||
siteName = sys.argv[1]
|
||||
if siteName[-4:] == '.log':
|
||||
siteName = siteName[:-4]
|
||||
else:
|
||||
siteName = siteName.replace("-access_log",'')
|
||||
oldFileName = logsPath+sys.argv[1]
|
||||
split_logs(oldFileName,num)
|
||||
|
||||
if is_nginx:
|
||||
os.system("kill -USR1 `cat /www/server/nginx/logs/nginx.pid`");
|
||||
else:
|
||||
os.system('/etc/init.d/httpd reload');
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/python
|
||||
#coding: utf-8
|
||||
#-----------------------------
|
||||
#宝塔Linux面板网站日志切割脚本
|
||||
#-----------------------------
|
||||
import sys
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
import glob
|
||||
os.chdir("/www/server/panel")
|
||||
sys.path.append('class/')
|
||||
import public
|
||||
print ('==================================================================')
|
||||
print( '★['+time.strftime("%Y/%m/%d %H:%M:%S")+'],切割日志')
|
||||
print ('==================================================================')
|
||||
print ('|--当前保留最新的['+sys.argv[2]+']份')
|
||||
logsPath = '/www/wwwlogs/'
|
||||
is_nginx = False
|
||||
if os.path.exists('/www/server/nginx/logs/nginx.pid'): is_nginx = True
|
||||
px = '.log'
|
||||
if not is_nginx: px = '-access_log'
|
||||
|
||||
def split_logs(oldFileName,num):
|
||||
global logsPath
|
||||
if not os.path.exists(oldFileName):
|
||||
print('|---'+oldFileName+'文件不存在!')
|
||||
return
|
||||
|
||||
logs=sorted(glob.glob(oldFileName+"_*"))
|
||||
count=len(logs)
|
||||
num=count - num
|
||||
|
||||
for i in range(count):
|
||||
if i>num: break;
|
||||
os.remove(logs[i])
|
||||
print('|---多余日志['+logs[i]+']已删除!')
|
||||
|
||||
newFileName=oldFileName+'_'+time.strftime("%Y-%m-%d_%H%M%S")+'.log'
|
||||
shutil.move(oldFileName,newFileName)
|
||||
print('|---已切割日志到:'+newFileName)
|
||||
|
||||
def split_all(save):
|
||||
sites = public.M('sites').field('name').select()
|
||||
for site in sites:
|
||||
oldFileName = logsPath + site['name'] + px
|
||||
split_logs(oldFileName,save)
|
||||
|
||||
if __name__ == '__main__':
|
||||
num = int(sys.argv[2])
|
||||
if sys.argv[1].find('ALL') == 0:
|
||||
split_all(num)
|
||||
else:
|
||||
siteName = sys.argv[1]
|
||||
if siteName[-4:] == '.log':
|
||||
siteName = siteName[:-4]
|
||||
else:
|
||||
siteName = siteName.replace("-access_log",'')
|
||||
oldFileName = logsPath+sys.argv[1]
|
||||
split_logs(oldFileName,num)
|
||||
|
||||
if is_nginx:
|
||||
os.system("kill -USR1 `cat /www/server/nginx/logs/nginx.pid`");
|
||||
else:
|
||||
os.system('/etc/init.d/httpd reload');
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
#+------------------------------------
|
||||
#+ 宝塔释放内存脚本
|
||||
#+------------------------------------
|
||||
|
||||
endDate=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
log="释放内存!"
|
||||
echo "★[$endDate] $log"
|
||||
echo '----------------------------------------------------------------------------'
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-52" ];then
|
||||
/etc/init.d/php-fpm-52 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-53" ];then
|
||||
/etc/init.d/php-fpm-53 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-54" ];then
|
||||
/etc/init.d/php-fpm-54 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-55" ];then
|
||||
/etc/init.d/php-fpm-55 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-56" ];then
|
||||
/etc/init.d/php-fpm-56 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-70" ];then
|
||||
/etc/init.d/php-fpm-70 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-71" ];then
|
||||
/etc/init.d/php-fpm-71 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-72" ];then
|
||||
/etc/init.d/php-fpm-72 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-73" ];then
|
||||
/etc/init.d/php-fpm-73 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/php-fpm-74" ];then
|
||||
/etc/init.d/php-fpm-74 reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/mysqld" ];then
|
||||
/etc/init.d/mysqld reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/nginx" ];then
|
||||
/etc/init.d/nginx reload
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/httpd" ];then
|
||||
/etc/init.d/httpd graceful
|
||||
fi
|
||||
|
||||
if [ -f "/etc/init.d/pure-ftpd" ];then
|
||||
pkill -9 pure-ftpd
|
||||
sleep 0.3
|
||||
/etc/init.d/pure-ftpd start 2>/dev/null
|
||||
fi
|
||||
|
||||
sync
|
||||
sleep 2
|
||||
sync
|
||||
echo 3 > /proc/sys/vm/drop_caches
|
||||
|
||||
echo '----------------------------------------------------------------------------'
|
||||
Reference in New Issue
Block a user