mirror of
https://github.com/netcccyun/dnsmgr.git
synced 2026-02-24 16:57:22 +08:00
Merge 5cbdcb9bf7 into 410a33e870
This commit is contained in:
commit
f5ffd807ba
85
README.md
85
README.md
@ -40,9 +40,9 @@ CF优选IP功能,添加优选IP任务
|
||||
|
||||
### 部署方法
|
||||
|
||||
* 从[Release](https://github.com/netcccyun/dnsmgr/releases)页面下载安装包
|
||||
* 从[GitHub](https://github.com/coolxitech/dnsmgr)页面下载源码
|
||||
|
||||
* 运行环境要求PHP7.4+,MySQL5.6+
|
||||
* 运行环境要求PHP8.0+,MySQL5.6+
|
||||
|
||||
* 设置网站运行目录为`public`
|
||||
|
||||
@ -84,86 +84,17 @@ location / {
|
||||
```
|
||||
|
||||
### Docker部署方法
|
||||
非原仓镜像,仅运行网站服务,数据库服务需要自行创建。
|
||||
|
||||
首先需要安装Docker,然后执行以下命令拉取镜像并启动(启动后监听8081端口):
|
||||
容器使用本地数据库需要获取Docker网络主机IP地址且不能使用`127.0.0.1`和`localhost`,一般默认是`172.17.0.1`。
|
||||
|
||||
首先需要安装Docker,然后执行以下命令拉取镜像并启动(启动后监听8000端口):
|
||||
|
||||
```
|
||||
docker run --name dnsmgr -dit -p 8081:80 -v /var/dnsmgr:/app/www netcccyun/dnsmgr
|
||||
docker run --name dnsmgr -dit -p 8000:8000 -v /var/dnsmgr:/app kpxyyyy/dnsmgr
|
||||
```
|
||||
|
||||
访问并安装好后如果容灾切换未自动启动,重启容器即可:
|
||||
|
||||
```
|
||||
docker restart dnsmgr
|
||||
```
|
||||
|
||||
### docker-compose部署方法
|
||||
|
||||
```
|
||||
version: '3'
|
||||
services:
|
||||
dnsmgr-web:
|
||||
container_name: dnsmgr-web
|
||||
stdin_open: true
|
||||
tty: true
|
||||
ports:
|
||||
- 8081:80
|
||||
volumes:
|
||||
- /volume1/docker/dnsmgr/web:/app/www
|
||||
image: netcccyun/dnsmgr
|
||||
depends_on:
|
||||
- dnsmgr-mysql
|
||||
networks:
|
||||
- dnsmgr-network
|
||||
|
||||
dnsmgr-mysql:
|
||||
container_name: dnsmgr-mysql
|
||||
restart: always
|
||||
ports:
|
||||
- 3306:3306
|
||||
volumes:
|
||||
- ./mysql/conf/my.cnf:/etc/mysql/my.cnf
|
||||
- ./mysql/logs:/logs
|
||||
- ./mysql/data:/var/lib/mysql
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=123456
|
||||
- TZ=Asia/Shanghai
|
||||
image: mysql:5.7
|
||||
networks:
|
||||
- dnsmgr-network
|
||||
|
||||
networks:
|
||||
dnsmgr-network:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
在运行之前请创建好目录
|
||||
```
|
||||
mkdir -p ./web
|
||||
mkdir -p ./mysql/conf
|
||||
mkdir -p ./mysql/logs
|
||||
mkdir -p ./mysql/data
|
||||
|
||||
vim mysql/conf/my.cnf
|
||||
[mysqld]
|
||||
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
|
||||
```
|
||||
|
||||
登陆mysql容器创建数据库
|
||||
```
|
||||
docker exec -it dnsmgr-mysql /bin/bash
|
||||
mysql -uroot -p123456
|
||||
create database dnsmgr;
|
||||
```
|
||||
|
||||
在install界面链接IP填写dnsmgr-mysql
|
||||
|
||||
推荐使用Nginx进行反向代理.
|
||||
### 版权信息
|
||||
|
||||
版权所有Copyright © 2023~2024 by 消失的彩虹海(https://blog.cccyun.cn)
|
||||
|
||||
### 其他推荐
|
||||
|
||||
- [彩虹云主机 - 免备案CDN/虚拟主机](https://www.cccyun.net/)
|
||||
- [小白云高防云服务器](https://www.xiaobaiyun.cn/aff/GMLPMFOV)
|
||||
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
namespace app\controller;
|
||||
|
||||
use PDO;
|
||||
use Exception;
|
||||
use app\BaseController;
|
||||
use think\facade\View;
|
||||
use PDO;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
|
||||
class Install extends BaseController
|
||||
{
|
||||
@ -15,23 +16,24 @@ class Install extends BaseController
|
||||
return '当前已经安装成功,如果需要重新安装,请手动删除根目录.env文件';
|
||||
}
|
||||
if(request()->isPost()){
|
||||
$mysql_host = input('post.mysql_host', null, 'trim');
|
||||
$mysql_port = intval(input('post.mysql_port', '3306'));
|
||||
$mysql_user = input('post.mysql_user', null, 'trim');
|
||||
$mysql_pwd = input('post.mysql_pwd', null, 'trim');
|
||||
$mysql_name = input('post.mysql_name', null, 'trim');
|
||||
$mysql_prefix = input('post.mysql_prefix', 'cloud_', 'trim');
|
||||
$admin_username = input('post.admin_username', null, 'trim');
|
||||
$admin_password = input('post.admin_password', null, 'trim');
|
||||
$mysql_host = Request::post('mysql_host');
|
||||
$mysql_port = intval(Request::post('mysql_port', '3306'));
|
||||
$mysql_user = Request::post('mysql_user', null, 'trim');
|
||||
$mysql_pwd = Request::post('mysql_pwd', null, 'trim');
|
||||
$mysql_name = Request::post('mysql_name', null, 'trim');
|
||||
$mysql_prefix = Request::post('mysql_prefix', 'cloud_', 'trim');
|
||||
$admin_username = Request::post('admin_username', null, 'trim');
|
||||
$admin_password = Request::post('admin_password', null, 'trim');
|
||||
|
||||
if(!$mysql_host || !$mysql_user || !$mysql_pwd || !$mysql_name || !$admin_username || !$admin_password){
|
||||
return json(['code'=>0, 'msg'=>'必填项不能为空']);
|
||||
}
|
||||
|
||||
$configdata = file_get_contents(app()->getRootPath().'.example.env');
|
||||
$configdata = str_replace(['{dbhost}','{dbname}','{dbuser}','{dbpwd}','{dbport}','{dbprefix}'], [$mysql_host, $mysql_name, $mysql_user, $mysql_pwd, $mysql_port, $mysql_prefix], $configdata);
|
||||
$configData = file_get_contents(app()->getRootPath().'.example.env');
|
||||
$configData = str_replace(['{dbhost}','{dbname}','{dbuser}','{dbpwd}','{dbport}','{dbprefix}'], [$mysql_host, $mysql_name, $mysql_user, $mysql_pwd, $mysql_port, $mysql_prefix], $configData);
|
||||
|
||||
try{
|
||||
$DB = Db::connect();
|
||||
$DB=new PDO("mysql:host=".$mysql_host.";dbname=".$mysql_name.";port=".$mysql_port,$mysql_user,$mysql_pwd);
|
||||
}catch(Exception $e){
|
||||
if($e->getCode() == 2002){
|
||||
@ -56,7 +58,9 @@ class Install extends BaseController
|
||||
$sqls[]="REPLACE INTO `".$mysql_prefix."config` VALUES ('sys_key', '".random(16)."')";
|
||||
$sqls[]="INSERT INTO `".$mysql_prefix."user` (`username`,`password`,`level`,`regtime`,`lasttime`,`status`) VALUES ('".addslashes($admin_username)."', '$password', 2, NOW(), NOW(), 1)";
|
||||
|
||||
$success=0;$error=0;$errorMsg=null;
|
||||
$success = 0;
|
||||
$error = 0;
|
||||
$errorMsg = null;
|
||||
foreach ($sqls as $value) {
|
||||
$value=trim($value);
|
||||
if(empty($value))continue;
|
||||
@ -70,7 +74,7 @@ class Install extends BaseController
|
||||
}
|
||||
}
|
||||
if(empty($errorMsg)){
|
||||
if(!file_put_contents(app()->getRootPath().'.env', $configdata)){
|
||||
if(!file_put_contents(app()->getRootPath().'.env', $configData)){
|
||||
return json(['code'=>0, 'msg'=>'保存失败,请确保网站根目录有写入权限']);
|
||||
}
|
||||
Cache::clear();
|
||||
|
||||
@ -17,13 +17,15 @@
|
||||
{
|
||||
"name": "yunwuxin",
|
||||
"email": "448901948@qq.com"
|
||||
}
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"topthink/framework": "^6.0.0",
|
||||
"topthink/think-orm": "^2.0",
|
||||
"topthink/think-view": "^1.0",
|
||||
"php": ">=8.0.0",
|
||||
"ext-pdo": "*",
|
||||
"topthink/framework": "^8.0",
|
||||
"topthink/think-orm": "^3.0",
|
||||
"topthink/think-filesystem": "^2.0",
|
||||
"topthink/think-view": "^2.0",
|
||||
"cccyun/think-captcha": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
@ -47,5 +49,11 @@
|
||||
"@php think service:discover",
|
||||
"@php think vendor:publish"
|
||||
]
|
||||
},
|
||||
"repositories": {
|
||||
"packagist": {
|
||||
"type": "composer",
|
||||
"url": "https://mirrors.aliyun.com/composer/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
56
dockerfile
Normal file
56
dockerfile
Normal file
@ -0,0 +1,56 @@
|
||||
# 使用 php:8.1.30-cli-alpine3.20 作为基础镜像
|
||||
FROM php:8.1.30-cli-alpine3.20
|
||||
|
||||
# 更改为阿里云的 Alpine 软件源并更新索引
|
||||
RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories \
|
||||
&& apk update \
|
||||
&& apk add --no-cache \
|
||||
supervisor \
|
||||
curl \
|
||||
bash \
|
||||
libzip-dev \
|
||||
libpng-dev \
|
||||
freetype-dev \
|
||||
libjpeg-turbo-dev \
|
||||
libwebp-dev \
|
||||
libxpm-dev \
|
||||
libavif-dev \
|
||||
gcc \
|
||||
g++ \
|
||||
make \
|
||||
autoconf \
|
||||
libc-dev \
|
||||
openssl-dev \
|
||||
libaio-dev \
|
||||
linux-headers \
|
||||
brotli-dev
|
||||
|
||||
RUN docker-php-ext-configure gd --with-jpeg --with-webp --with-xpm --with-avif --with-freetype=/usr/include/freetype2 --with-jpeg=/usr/include\
|
||||
&& docker-php-ext-install gd \
|
||||
&& docker-php-ext-install zip \
|
||||
&& docker-php-ext-install pdo pdo_mysql \
|
||||
&& docker-php-ext-enable opcache \
|
||||
&& pecl install swoole \
|
||||
&& docker-php-ext-enable swoole \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
# 将应用程序代码复制到容器中
|
||||
COPY . /app
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
# 安装composer
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||
# 安装项目依赖
|
||||
RUN composer install --no-interaction --no-dev --optimize-autoloader
|
||||
# 暴露端口
|
||||
EXPOSE 8000
|
||||
# 复制计划任务配置文件
|
||||
COPY scripts/opiptask /etc/crontabs/root
|
||||
# 复制进程守护配置文件
|
||||
COPY scripts/supervisord.conf /etc/supervisord.conf
|
||||
# 授权启动脚本
|
||||
RUN chmod +x /app/scripts/run_tasks.sh
|
||||
# 复制opcache配置文件
|
||||
COPY scripts/opcache.ini /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
|
||||
# 运行进程守护应用
|
||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
||||
11
scripts/opcache.ini
Normal file
11
scripts/opcache.ini
Normal file
@ -0,0 +1,11 @@
|
||||
zend_extension=opcache
|
||||
; Enable OPcache extension
|
||||
opcache.enable = 1
|
||||
opcache.memory_consumption=128
|
||||
opcache.interned_strings_buffer=32
|
||||
opcache.max_accelerated_files=80000
|
||||
opcache.revalidate_freq=3
|
||||
opcache.fast_shutdown=1
|
||||
opcache.enable_cli=1
|
||||
opcache.jit_buffer_size=128m
|
||||
opcache.jit=1205
|
||||
1
scripts/opiptask
Normal file
1
scripts/opiptask
Normal file
@ -0,0 +1 @@
|
||||
*/15 * * * * php /app/think opiptask >> /var/log/cron.log 2>&1
|
||||
15
scripts/run_tasks.sh
Normal file
15
scripts/run_tasks.sh
Normal file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 检查文件是否存在
|
||||
if [ -f "/app/.env" ]; then
|
||||
echo "已安装网站, 开始执行计划任务和进程守护."
|
||||
|
||||
# 启动 crond
|
||||
/usr/sbin/crond
|
||||
|
||||
# 启动 dmtask
|
||||
php /app/think dmtask
|
||||
else
|
||||
echo "未安装网站, 跳过计划任务和进程守护."
|
||||
exit 0
|
||||
fi
|
||||
14
scripts/supervisord.conf
Normal file
14
scripts/supervisord.conf
Normal file
@ -0,0 +1,14 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
|
||||
[program:web]
|
||||
command=php /app/think run
|
||||
autostart=true
|
||||
autorestart=true
|
||||
|
||||
[program:check_tasks]
|
||||
command=bash /app/scripts/run_tasks.sh
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=99999 ; 设置为一个很大的值
|
||||
startsecs=5 ; 启动后等待时间
|
||||
Loading…
Reference in New Issue
Block a user