mirror of https://github.com/IoTcat/PyOne.git
parent
0d016f0a2c
commit
2872b1a394
15 changed files with 688 additions and 199 deletions
@ -0,0 +1,74 @@ |
||||
{%extends 'admin/layout.html'%} |
||||
|
||||
{%block content%} |
||||
<div class="mdui-container-fluid"> |
||||
<div class="mdui-typo"> |
||||
<h1>系统安装 <small>MongoDB信息配置</small></h1> |
||||
</div> |
||||
|
||||
<div class="mdui-row"> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">主机(默认localhost)</label> |
||||
<input name="MONGO_HOST" id="MONGO_HOST" class="mdui-textfield-input" type="text" value="{{GetConfig('MONGO_HOST')}}" required="" /> |
||||
</div> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">端口号(默认27017)</label> |
||||
<input name="MONGO_PORT" id="MONGO_PORT" class="mdui-textfield-input" type="text" value="{{GetConfig('MONGO_PORT')}}" required="" /> |
||||
</div> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">数据库(默认为three)</label> |
||||
<input name="MONGO_DB" id="MONGO_DB" class="mdui-textfield-input" type="text" value="{{GetConfig('MONGO_DB')}}" required="" /> |
||||
</div> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">用户名(宝塔安装的默认为空)</label> |
||||
<input name="MONGO_USER" id="MONGO_USER" class="mdui-textfield-input" type="text" value="{{GetConfig('MONGO_USER')}}" /> |
||||
</div> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">密码(宝塔安装的默认为空)</label> |
||||
<input name="MONGO_PASSWORD" id="MONGO_PASSWORD" class="mdui-textfield-input" type="text" value="{{GetConfig('MONGO_PASSWORD')}}" /> |
||||
</div> |
||||
|
||||
<div class="mdui-col-xs-2" style="padding-top: 34px;"> |
||||
<button onclick="test_mongo()" class="mdui-btn mdui-btn-block mdui-color-red-600 mdui-ripple"> |
||||
提交 |
||||
</button> |
||||
</div> |
||||
</div> |
||||
<hr> |
||||
|
||||
</div> |
||||
<script type="text/javascript"> |
||||
function ShowNotice(msg){ |
||||
mdui.snackbar({ |
||||
message: msg, |
||||
position: 'top' |
||||
}); |
||||
} |
||||
|
||||
function test_mongo() { |
||||
MONGO_HOST=$("#MONGO_HOST").val(); |
||||
MONGO_PORT=$("#MONGO_PORT").val(); |
||||
MONGO_DB=$("#MONGO_DB").val(); |
||||
MONGO_USER=$("#MONGO_USER").val(); |
||||
MONGO_PASSWORD=$("#MONGO_PASSWORD").val(); |
||||
var index2 = layer.load(2, { |
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景 |
||||
}); |
||||
$.ajax({ |
||||
type: "POST", |
||||
url: "{{url_for('admin.test_config')}}", |
||||
data:{soft:'mongo',host:MONGO_HOST,port:MONGO_PORT,user:MONGO_USER,password:MONGO_PASSWORD,db:MONGO_DB}, |
||||
dataType: "json", |
||||
success: function(data) { |
||||
ShowNotice(data.msg); |
||||
layer.close(index2); |
||||
if(data.code==1){ |
||||
window.location.href=window.location.href.replace('step=0','step=1'); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
} |
||||
|
||||
</script> |
||||
{%endblock content%} |
@ -0,0 +1,68 @@ |
||||
{%extends 'admin/layout.html'%} |
||||
|
||||
{%block content%} |
||||
<div class="mdui-container-fluid"> |
||||
<div class="mdui-typo"> |
||||
<h1>系统安装 <small>Redis信息配置</small></h1> |
||||
</div> |
||||
|
||||
<div class="mdui-row"> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">主机(默认localhost)</label> |
||||
<input name="REDIS_HOST" id="REDIS_HOST" class="mdui-textfield-input" type="text" value="{{GetConfig('REDIS_HOST')}}" required="" /> |
||||
</div> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">端口号(默认6379)</label> |
||||
<input name="REDIS_PORT" id="REDIS_PORT" class="mdui-textfield-input" type="text" value="{{GetConfig('REDIS_PORT')}}" required="" /> |
||||
</div> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">数据库(默认值为0)</label> |
||||
<input name="REDIS_DB" id="REDIS_DB" class="mdui-textfield-input" type="text" value="{{GetConfig('REDIS_DB')}}" required="" /> |
||||
</div> |
||||
<div class="mdui-col-xs-2"> |
||||
<label class="mdui-textfield-label">密码(宝塔安装的默认为空)</label> |
||||
<input name="REDIS_PASSWORD" id="REDIS_PASSWORD" class="mdui-textfield-input" type="text" value="{{GetConfig('REDIS_PASSWORD')}}" /> |
||||
</div> |
||||
|
||||
<div class="mdui-col-xs-2" style="padding-top: 34px;"> |
||||
<button onclick="test_redis()" class="mdui-btn mdui-btn-block mdui-color-red-600 mdui-ripple"> |
||||
提交 |
||||
</button> |
||||
</div> |
||||
</div> |
||||
<hr> |
||||
|
||||
</div> |
||||
<script type="text/javascript"> |
||||
function ShowNotice(msg){ |
||||
mdui.snackbar({ |
||||
message: msg, |
||||
position: 'top' |
||||
}); |
||||
} |
||||
|
||||
function test_redis() { |
||||
REDIS_HOST=$("#REDIS_HOST").val(); |
||||
REDIS_PORT=$("#REDIS_PORT").val(); |
||||
REDIS_DB=$("#REDIS_DB").val(); |
||||
REDIS_PASSWORD=$("#REDIS_PASSWORD").val(); |
||||
var index2 = layer.load(2, { |
||||
shade: [0.1, '#fff'] //0.1透明度的白色背景 |
||||
}); |
||||
$.ajax({ |
||||
type: "POST", |
||||
url: "{{url_for('admin.test_config')}}", |
||||
data:{soft:'redis',host:REDIS_HOST,port:REDIS_PORT,password:REDIS_PASSWORD,db:REDIS_DB}, |
||||
dataType: "json", |
||||
success: function(data) { |
||||
ShowNotice(data.msg); |
||||
layer.close(index2); |
||||
if(data.code==1){ |
||||
window.location.href=window.location.href.replace('step=1','step=2'); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
} |
||||
</script> |
||||
{%endblock content%} |
@ -1,130 +1,295 @@ |
||||
#!/etc/bash |
||||
function wget_exists(){ |
||||
echo "1. 安装wget"; |
||||
which wget > /dev/null 2>&1 |
||||
if [ $? == 0 ]; then |
||||
echo "wget exist" |
||||
else |
||||
echo "wget dose not exist" |
||||
yum install wget -y |
||||
#!/bin/bash |
||||
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
||||
|
||||
# ==================================================== |
||||
# Description:PyOne 一键脚本 for Debian 8+ 、CentOS 7、Ubuntu 16+ |
||||
# ==================================================== |
||||
|
||||
#fonts color |
||||
Red="\033[31m" |
||||
Font="\033[0m" |
||||
Blue="\033[36m" |
||||
|
||||
|
||||
check_port() { |
||||
netstat -tlpn | grep "\b$1\b" |
||||
} |
||||
#root permission |
||||
check_root(){ |
||||
if [[ $EUID -ne 0 ]]; then |
||||
echo "${Red}Error:请使用root运行该脚本!"${Font} 1>&2 |
||||
exit 1 |
||||
fi |
||||
} |
||||
|
||||
#check system |
||||
check_system(){ |
||||
if [[ -f /etc/redhat-release ]]; then |
||||
release="centos" |
||||
elif cat /etc/issue | grep -Eqi "debian"; then |
||||
release="debian" |
||||
elif cat /etc/issue | grep -Eqi "ubuntu"; then |
||||
release="ubuntu" |
||||
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then |
||||
release="centos" |
||||
elif cat /proc/version | grep -Eqi "debian"; then |
||||
release="debian" |
||||
elif cat /proc/version | grep -Eqi "ubuntu"; then |
||||
release="ubuntu" |
||||
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then |
||||
release="centos" |
||||
fi |
||||
} |
||||
|
||||
function git_exists(){ |
||||
echo "2. 安装git"; |
||||
which git > /dev/null 2>&1 |
||||
if [ $? == 0 ]; then |
||||
echo "git exist" |
||||
#check version |
||||
check_version(){ |
||||
if [[ -s /etc/redhat-release ]]; then |
||||
version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'` |
||||
else |
||||
version=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1` |
||||
fi |
||||
bit=`uname -m` |
||||
if [[ ${bit} = "x86_64" ]]; then |
||||
bit="64" |
||||
else |
||||
echo "git dose not exist" |
||||
yum install git -y |
||||
bit="32" |
||||
fi |
||||
if [[ "${release}" = "centos" && ${version} -ge 7 ]];then |
||||
echo -e "${Blue}当前系统为CentOS ${version}${Font} " |
||||
elif [[ "${release}" = "debian" && ${version} -ge 8 ]];then |
||||
echo -e "${Blue}当前系统为Debian ${version}${Font} " |
||||
elif [[ "${release}" = "ubuntu" && ${version} -ge 16 ]];then |
||||
echo -e "${Blue}当前系统为Ubuntu ${version}${Font} " |
||||
else |
||||
echo -e "${Red}脚本不支持当前系统,安装中断!${Font} " |
||||
exit 1 |
||||
fi |
||||
for EXE in grep cut xargs systemctl ip awk |
||||
do |
||||
if ! type -p ${EXE}; then |
||||
echo -e "${Red}系统精简厉害,脚本自动退出${Font}" |
||||
exit 1 |
||||
fi |
||||
done |
||||
} |
||||
#安装pip |
||||
function pip_exists(){ |
||||
echo "3. 安装pip"; |
||||
which pip > /dev/null 2>&1 |
||||
if [ $? == 0 ]; then |
||||
echo "pip exist" |
||||
|
||||
|
||||
check_service(){ |
||||
read -p "请输入redis端口号[6379]:" redis_port |
||||
if [ -z "${redis_port}" ];then |
||||
redis_port=6379 |
||||
fi |
||||
|
||||
read -p "请输入redis端口号[27017]:" mongo_port |
||||
|
||||
if [ -z "${mongo_port}" ];then |
||||
mongo_port=27017 |
||||
fi |
||||
|
||||
|
||||
if check_port ${redis_port}; then |
||||
echo "" |
||||
else |
||||
echo "pip dose not exist" |
||||
wget https://bootstrap.pypa.io/get-pip.py |
||||
python get-pip.py |
||||
rm -rf get-pip.py |
||||
echo -e "${Red}Error:请先在宝塔安装redis"${Font} 1>&2 |
||||
exit 1 |
||||
fi |
||||
|
||||
if check_port ${mongo_port}; then |
||||
echo "" |
||||
else |
||||
echo -e "${Red}Error:请先在宝塔安装MongoDB"${Font} 1>&2 |
||||
exit 1 |
||||
fi |
||||
} |
||||
|
||||
#安装python依赖包 |
||||
function install_(){ |
||||
echo "4. 安装python依赖包"; |
||||
pip install -r requirements.txt -U |
||||
#enter info |
||||
enter(){ |
||||
stty erase '^H' && read -p "请设置Aria2密钥:" aria2_pass |
||||
sed -i "s/ARIA2_SECRET=\"abbey\"/ARIA2_SECRET=\"${aria2_pass}\"/g" self_config.py |
||||
|
||||
read -p "请设置PyOne的后台密码:" pyone_pass |
||||
sed -i "s/password=\"PyOne\"/password=\"${pyone_pass}\"/g" self_config.py |
||||
} |
||||
|
||||
#配置文件 |
||||
function config_file(){ |
||||
echo "5. 配置文件"; |
||||
|
||||
config_file(){ |
||||
cur_dir=`pwd` |
||||
cp self_config.py.sample self_config.py |
||||
cp supervisord.conf.sample supervisord.conf |
||||
mkdir /var/run/supervisor |
||||
chmod +x /var/run/supervisor |
||||
sed -i "s|/root/PyOne|$cur_dir|" self_config.py |
||||
sed -i "s|/root/PyOne|$cur_dir|" supervisord.conf |
||||
} |
||||
|
||||
#添加开机任务 |
||||
function auto_boot(){ |
||||
echo "6. 配置开机启动"; |
||||
cur_dir=`pwd` |
||||
echo "supervisord -c $cur_dir/supervisord.conf" >> /etc/rc.d/rc.local |
||||
echo "sh /data/aria2/aria2.sh start" >> /etc/rc.d/rc.local |
||||
chmod +x /etc/rc.d/rc.local |
||||
# sh /data/arai2/aria2.sh start |
||||
} |
||||
|
||||
|
||||
#安装aria2 |
||||
function install_aria2(){ |
||||
echo "7. 安装aria2"; |
||||
which aria2c > /dev/null 2>&1 |
||||
if [ $? == 0 ]; then |
||||
echo "检测到已安装aria2" |
||||
echo "请到后台配置aria2信息" |
||||
echo "如果您配置了aria2授权信息,请确保是rpc-secret模式!如果不是,则不能正常工作。" |
||||
echo "开启rpc-secret模式方法:" |
||||
echo " >1. 编辑aria2的配置文件,将rpc-secret这一行反注释,然后'rpc-secret='后面填写密码" |
||||
echo " >2. 将rpc-user和rpc-passwd注释掉" |
||||
echo " >3. 重启aria2" |
||||
#install depend |
||||
install_depend(){ |
||||
echo -e "${Blue}开始安装依赖${Font}" |
||||
if [[ "${release}" = "centos" ]]; then |
||||
yum -y install make git gcc crontabs lsof unzip python-devel libffi-devel openssl-devel -y |
||||
else |
||||
git clone https://github.com/abbeyokgo/aria2_installer.git |
||||
cd aria2_installer |
||||
sh install_aria2.sh |
||||
echo "安装aria2完成" |
||||
echo "如果已经成功安装,请到后台配置aria2信息" |
||||
cd .. |
||||
rm -rf aria2_installer |
||||
apt update -y |
||||
apt install -y make git cron build-essential python-dev lsof unzip python-setuptools python-wheel libffi-devel libssl-dev |
||||
fi |
||||
} |
||||
|
||||
#开放端口 |
||||
function open_port(){ |
||||
if [ -e "/etc/sysconfig/iptables" ] |
||||
then |
||||
iptables -I INPUT -p tcp --dport 34567 -j ACCEPT |
||||
service iptables save |
||||
service iptables restart |
||||
|
||||
#install aria2 |
||||
install_aria2(){ |
||||
echo -e "${Blue}开始安装Aria2...${Font}" |
||||
wget -N --no-check-certificate https://www.moerats.com/usr/shell/PyOne/aria2-1.34.0-linux-${bit}.tar.gz |
||||
tar zxvf aria2-1.34.0-linux-${bit}.tar.gz |
||||
rm -rf aria2-1.34.0-linux-${bit}.tar.gz |
||||
cd aria2-1.34.0-linux-${bit} |
||||
make install |
||||
EXEC="$(command -v aria2c)" |
||||
if [[ -n ${EXEC} ]]; then |
||||
echo -e "${Blue}Aria2安装成功!${Font}" |
||||
else |
||||
firewall-cmd --zone=public --add-port=34567/tcp --permanent |
||||
firewall-cmd --reload |
||||
echo -e "${Red}Aria2安装失败!${Font}" |
||||
exit 1 |
||||
fi |
||||
cd .. |
||||
rm -rf aria2-1.34.0-linux-${bit} |
||||
mkdir "/root/.aria2" && mkdir /root/Download |
||||
wget -N --no-check-certificate https://www.moerats.com/usr/shell/Aria2/dht.dat -P '/root/.aria2/' |
||||
wget -N --no-check-certificate https://www.moerats.com/usr/shell/PyOne/aria2.conf -P '/root/.aria2/' |
||||
wget -N --no-check-certificate https://www.moerats.com/usr/shell/PyOne/trackers-list-aria2.sh -P '/root/.aria2/' |
||||
touch /root/.aria2/aria2.session |
||||
chmod +x /root/.aria2/trackers-list-aria2.sh |
||||
chmod 777 /root/.aria2/aria2.session |
||||
sed -i "s/rpc-secret=/rpc-secret=${pass}/g" /root/.aria2/aria2.conf |
||||
echo -e "${Blue}开始设置trackers-list自动更新!${Font}" |
||||
if [[ "${release}" = "centos" ]]; then |
||||
echo "0 0 */7 * * /root/.aria2/trackers-list-aria2.sh" >> /var/spool/cron/root |
||||
else |
||||
echo "0 0 */7 * * /root/.aria2/trackers-list-aria2.sh" >> /var/spool/cron/crontabs/root |
||||
fi |
||||
} |
||||
|
||||
#install pyone |
||||
install_pip(){ |
||||
echo -e "${Blue}正在安装pip!${Font}" |
||||
if [[ "${release}" = "centos" ]]; then |
||||
yum install -y python-pip |
||||
EXEC="$(command -v pip)" |
||||
if [[ -z ${EXEC} ]]; then |
||||
wget https://bootstrap.pypa.io/get-pip.py |
||||
python get-pip.py |
||||
fi |
||||
else |
||||
apt -y install python-pip |
||||
fi |
||||
EXEC="$(command -v pip)" |
||||
if [[ -n ${EXEC} ]]; then |
||||
echo -e "${Blue}pip安装成功!${Font}" |
||||
else |
||||
echo -e "${Red}pip安装失败!${Font}" |
||||
exit 1 |
||||
fi |
||||
|
||||
} |
||||
|
||||
install_package(){ |
||||
pip2 install -r requirements.txt |
||||
} |
||||
|
||||
|
||||
|
||||
#open firewall |
||||
firewall(){ |
||||
if [[ "${release}" = "centos" ]]; then |
||||
firewall-cmd --zone=public --add-port=6800/tcp --permanent |
||||
firewall-cmd --zone=public --add-port=34567/tcp --permanent |
||||
firewall-cmd --zone=public --add-port=80/tcp --permanent |
||||
firewall-cmd --zone=public --add-port=443/tcp --permanent |
||||
firewall-cmd --reload |
||||
fi |
||||
} |
||||
|
||||
|
||||
|
||||
#set start up |
||||
start(){ |
||||
echo -e "${Blue}正在为相关应用设置开机自启!${Font}" |
||||
echo "[Unit] |
||||
Description=Aria2 server |
||||
After=network.target |
||||
Wants=network.target |
||||
|
||||
[Service] |
||||
Type=simple |
||||
PIDFile=/var/run/aria2c.pid |
||||
ExecStart=/usr/bin/aria2c --conf-path=/root/.aria2/aria2.conf |
||||
RestartPreventExitStatus=23 |
||||
Restart=always |
||||
User=root |
||||
|
||||
[Install] |
||||
WantedBy=multi-user.target |
||||
" > '/etc/systemd/system/aria2.service' |
||||
|
||||
echo "[Unit] |
||||
Description=pyone |
||||
After=network.target |
||||
Wants=network.target |
||||
|
||||
#执行 |
||||
install_ |
||||
config_file |
||||
#auto_boot |
||||
#install_aria2 |
||||
open_port |
||||
yum install gcc libffi-devel python-devel openssl-devel -y |
||||
yum install lsof -y |
||||
mkdir logs |
||||
echo "---------------------------------------------------------------" |
||||
echo "一键脚本运行完成!请检查以下文件:" |
||||
echo " > 1. self_config.py、supervisord.conf是否存在!" |
||||
echo " > 2. 检查self_config.py、supervisord.conf脚本里面的目录是否正确!" |
||||
echo " > 3. 请确保已经安装Nginx、Redis、MongoDB,并已经运行!" |
||||
echo " > 4. 检查/data/aria2是否存在。" |
||||
echo " > 5. 检查aria2是否运行:pgrep 'aria2c'" |
||||
echo " 如果aria2没有运行,运行:sh /data/aria2/aria2.sh start" |
||||
echo |
||||
echo "如果检查没有问题!在网站目录可运行以下脚本运行网站" |
||||
echo "supervisord -c supervisord.conf" |
||||
echo "---------------------------------------------------------------" |
||||
echo |
||||
echo "PyOne交流群:864996565" |
||||
echo "PyOne交流群TG:https://t.me/joinchat/JQOOug6MY11gy_MiXTmqIA" |
||||
[Service] |
||||
Type=simple |
||||
PIDFile=/var/run/pyone.pid |
||||
WorkingDirectory=/root/PyOne |
||||
ExecStart=gunicorn -keventlet -b 0.0.0.0:34567 run:app |
||||
RestartPreventExitStatus=23 |
||||
Restart=always |
||||
User=root |
||||
|
||||
[Install] |
||||
WantedBy=multi-user.target |
||||
" > '/etc/systemd/system/pyone.service' |
||||
|
||||
EXEC="$(command -v gunicorn)" |
||||
sed -i "s#gunicorn#${EXEC}#g" /etc/systemd/system/pyone.service |
||||
systemctl start aria2 pyone |
||||
systemctl enable aria2 pyone |
||||
} |
||||
|
||||
#Complete info |
||||
info(){ |
||||
local_ip=`curl http://whatismyip.akamai.com` |
||||
echo -e "———————————————————————————————————————" |
||||
echo -e "${Blue}PyOne安装完成!${Font}" |
||||
echo -e "${Blue}请通过访问:http://${local_ip}:34567 继续后面的安装${Font}" |
||||
echo -e "${Blue}PyOne后台密码:${pyone_pass}${Font}" |
||||
echo -e "${Blue}Aria2密匙:${aria2_pass}${Font}" |
||||
echo -e "${Blue}常用命令:${Font}" |
||||
echo -e "${Blue}1. 暂停PyOne: systemctl stop pyone${Font}" |
||||
echo -e "${Blue}2. 启动PyOne: systemctl start pyone${Font}" |
||||
echo -e "${Blue}3. 重启PyOne: systemctl restart pyone${Font}" |
||||
echo -e "${Blue}4. 手动运行PyOne: systemctl stop pyone && gunicorn -keventlet -b 0:34567 run:app${Font}" |
||||
echo -e "———————————————————————————————————————" |
||||
echo -e "${Blue}PyOne交流群:864996565${Font}" |
||||
echo -e "${Blue}PyOne交流群TG:https://t.me/joinchat/JQOOug6MY11gy_MiXTmqIA${Font}" |
||||
} |
||||
|
||||
#start menu |
||||
main(){ |
||||
check_root |
||||
check_system |
||||
check_version |
||||
check_service |
||||
clear |
||||
echo -e "———————————————————————————————————————" |
||||
echo -e "${Blue}PyOne一键脚本 for Debian 8+ 、CentOS 7、Ubuntu 16+${Font}" |
||||
echo -e "本脚本参考【萌鼠博客】:https://www.moerats.com/archives/806/" |
||||
echo -e "${Blue}安装之前请确保已经在安装宝塔,并且在宝塔-软件管理已经安装MongoDB和redis${Font}" |
||||
echo -e "———————————————————————————————————————" |
||||
config_file |
||||
enter |
||||
install_depend |
||||
install_aria2 |
||||
install_pip |
||||
install_package |
||||
firewall |
||||
start |
||||
info |
||||
} |
||||
|
||||
main |
||||
|
Loading…
Reference in new issue