2020年7月

ERROR: Version in "./docker-compose.yml" is invalid. Either specify a version of "2" (or "2.0") and place your service definitions under the services key, or omit the version key and place your service definitions at the root of the file to use version 1.
[root@localhost course2]# docker-compose -v
docker-compose version 1.7.0, build 0d7bf73
[root@localhost course2]# docker-compose down && docker-compose up -d
ERROR: Version in "./docker-compose.yml" is invalid. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
[root@localhost course2]# curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   638  100   638    0     0    400      0  0:00:01  0:00:01 --:--:--   400
 34 11.2M   34 3943k    0     0   5294      0  0:36:59  0:12:42  0:24:17     0
curl: (56) OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104
[root@localhost course2]# docker-compose down && docker-compose up -d --build 2.0
[30751] Cannot open self /usr/local/bin/docker-compose or archive /usr/local/bin/docker-compose.pkg
[root@localhost course2]# curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   638  100   638    0     0    425      0  0:00:01  0:00:01 --:--:--   425
100 11.2M  100 11.2M    0     0  15073      0  0:12:59  0:12:59 --:--:-- 17374
[root@localhost course2]# docker-compose -v
docker-compose version 1.23.2, build 1110ad01

阿里云的LINUX中安装办法

[root@xgblog ~]# yum install docker-compose -y
. . . 
Complete!
[root@xgblog ~]# docker-compose -v
bash: /usr/local/bin/docker-compose: Permission denied
[root@xgblog ~]# chmod +x /usr/local/bin/docker-compose
[root@xgblog ~]# docker-compose -v
docker-compose version 1.23.2, build 1110ad01

不行的话再加软链
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

  • 错误如下
Thu Jul 16 16:39:38 2020 Route addition fallback to route.exe
请求的操作需要提升。
Thu Jul 16 16:39:38 2020 ERROR: Windows route add command failed [adaptive]: returned error code 1
Thu Jul 16 16:39:38 2020 C:\WINDOWS\system32\route.exe ADD 192.168.2.0 MASK 255.255.255.0 10.8.0.1
Thu Jul 16 16:39:38 2020 ROUTE: route addition failed using CreateIpForwardEntry: 拒绝访问。   [status=5 if_index=10]
Thu Jul 16 16:39:38 2020 Route addition via IPAPI failed [adaptive]
Thu Jul 16 16:39:38 2020 Route addition fallback to route.exe

后来参考各方文章后发现, 这个10段的网络没有网关ip, cmd里面执行

C:\Users\Administrator>route ADD 192.168.2.0 MASK 255.255.255.0 10.8.0.254
请求的操作需要提升。

后来修改了openvpn的快捷方式, 在兼容性里面勾选了 以管理员身份运行此程序, 重新打开程序, 终于问题解决了

  • 创建php文件并执行测试 vi mailtest.php
<?php
function getHost($host)
{  //解析域名
    $getHost = gethostbyname($host);
    echo "尝试连接 $host ...<br>\r\n ";
    if (!$getHost) {
        echo "解析失败 (1)<HR>";
    } elseif ($getHost == $host) {
        echo "解析失败 (2): 可能是一个无效的主机名<HR>";
    } else {
        echo "域名解析为 $getHost ...<br>\r\n";
        openHost($host);
    }
}

function openHost($host)
{  //连接主机

    if (function_exists('fsockopen')) {
        $fp = fsockopen($host, 25, $errno, $errstr, 60);
    } elseif (function_exists('pfsockopen')) {
        echo "服务器不支持Fsockopen,尝试pFsockopen函数 ...<br>\r\n";
        $fp = pfsockopen($host, 25, $errno, $errstr, 60);
    } else
        exit('服务器不支持Fsockopen函数');

    if (!$fp) {
        echo "代号:$errno,<br>\n错误原因:$errstr<HR>";
    } else {
        echo "SMTP服务器连接ok!<br>\r\n";
        fwrite($fp, "");
        $out0 = fgets($fp, 128);
#echo $out0;
        foreach (["220"] as $port) {
            if (strncmp($out0, $port, 3) == 0) { // 判断三位字符内容
                echo $port . ' SMTP服务端响应正常<HR>';
            } else {
                echo $port . '服务器端错误<HR>';
            }
        }
    }
}

//SMTP服务器地址

foreach (["smtp.163.com", "smtp.sina.cn", "smtp.sina.com", "smtp.qq.com", "smtp.126.com", "smtp.gmail.com"] as $host) {
    echo getHost($host) . "\n\n\n";
}

if (function_exists('mail')) {
    echo 'mail方法正常';
}

如果以上正常,那么就检查是否邮箱帐号的问题

  • 查看是否开启openssl
php -r 'echo !extension_loaded('openssl')?"Not Available":"Available";';
执行结果
PHP Warning:  Use of undefined constant openssl - assumed 'openssl' (this will throw an Error in a future version of PHP) in Command line code on line 1
后来发现把内容写入到php文件中执行正常的
  • 未配置CA证书的情况
先查询配置文件路径
bash-4.4# php -i | grep cafile
openssl.cafile => no value => no value

创建ca文件, 把下载的CA文件的内容粘贴进去 [下载最新的CA cert文件](https://curl.haxx.se/ca/cacert.pem)
vi /etc/ssl/cacert.pem

修改php配置文件, 添加下面的内容
bash-4.4# vi /etc/php7/php.ini
openssl.cafile = /etc/ssl/cacert.pem
curl.cainfo = /etc/ssl/cacert.pem

判断是否开启openssl
php -m | grep openssl
如果没有开启,搜索php.ini下面内容, 把前面的;删除
extension=openssl


再次确认配置是否生效
bash-4.4# php -i | grep cafile
openssl.cafile => /etc/ssl/cacert.pem => /etc/ssl/cacert.pem
  • 最终还是查到了原因, 配置的域名邮箱的域名解析的关联mx值丢失导致的
MX记录
未设置或暂未生效

参考链接: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

  • 创建 index.php 发布入口文件
<?php
if (empty($_SERVER['DOCUMENT_ROOT']) || strpos($_SERVER['DOCUMENT_ROOT'], ':') === false) {
    $hostSystem = 'linux';
} else {
    $hostSystem = 'windows';
}
echo '<h1><a href="">系统版本: ' . $hostSystem . '</a></h1>';

$baseDir = dirname(__FILE__, 2);
$baseDir = str_replace('\\', '/', $baseDir);
$dirs = scandir($baseDir);
unset($dirs[0]);
unset($dirs[1]);
$dirList = [];
foreach ($dirs as $key => $dir) {
    if (!is_dir($baseDir . '/' . $dir . '/.git')) {
        unset($dirs[$key]);
    } else {
        $dirListItem = [
            'value' => $dir,
            'app_type' => '',
        ];
        if (file_exists($baseDir . '/' . $dir . '/src/public/index.php') || file_exists($baseDir . '/' . $dir . '/public/index.php')) {
            $dirListItem['app_type'] = 'laravel';
        } else if (is_dir($baseDir . '/' . $dir . '/src/runtime') || is_dir($baseDir . '/' . $dir . '/runtime')) {
            $dirListItem['app_type'] = 'hyperf';
        } else {
            $dirListItem['app_type'] = 'front';
        }
        $dirList[$dir] = $dirListItem;
    }
}
$dirs = array_values($dirs);
$requestMethod = empty($_SERVER['REQUEST_METHOD']) ? 'GET' : $_SERVER['REQUEST_METHOD'];
switch ($requestMethod) {
    case 'GET':
        echo '<form action="" method="POST">
<h3>选择需要执行的目录: </h3>
';
        $dirLists = [];
        foreach ($dirList as $dirListItem) {
            $dirLists[$dirListItem['app_type']][] = $dirListItem;
        }
        foreach ($dirLists as $appType => $dirList) {
            echo '<h2><font style="color: blue;">' . $appType . '</font></h2>';
            foreach ($dirList as $dirListItem) {
                echo '<label><input type="radio" name="dir" value="' . $dirListItem['value'] . '">' . $dirListItem['value'] . '</label>';
            }
        }
        echo '
<br><input type="submit" value="执行">
</form>
<style>
    label{
        font-weight: lighter;
    }
</style>';
        break;
    case 'POST':
        // 执行发布
        $request = $_REQUEST;
        $dir = empty($_POST['dir']) ? '' : $_POST['dir'];
        if (empty($dir)) {
            die('请选择目录');
        }
        if (empty($dirList[$dir])) {
            die('目录不在白名单中');
        }

        $cmd = [];

        $appType = $dirList[$dir]['app_type'];
        $startTTL = microtime(true);
        echo "<pre>";
        if ($hostSystem == 'windows') {
        } else {
            $da = [];

            $branch = 'develop';
            $branch = 'master';
            switch ($appType) {
                case 'hyperf':
                    $shell = 'sudo ' . dirname(__FILE__) . '/php_deploy_hyperf.sh ' . $dir . ' ' . $branch;
                    echo '<h3>' . $shell . '</h3>';
                    system($shell, $status);
                    break;
                case 'laravel':
                    $shell = 'sudo ' . dirname(__FILE__) . '/php_deploy_laravel.sh ' . $dir . ' ' . $branch;
                    echo '<h3>' . $shell . '</h3>';
                    system($shell, $status);
                    break;
                case 'front':
                    $shell = 'sudo ' . dirname(__FILE__) . '/php_deploy_front.sh ' . $dir . ' ' . $branch;
                    echo '<h3>' . $shell . '</h3>';
                    system($shell, $status);
                    break;
                default:
                    die('未能识别需要执行的代码类型');
            }
        }
        echo '用时: ' . intval((microtime(true) - $startTTL) * 1000) / 1000;
        echo '</pre>';
        if ($status) {
            echo "执行失败";
        } else {
            echo "执行成功";
        }
        break;
}
  • vim 前端用到的发布文件 vim php_deploy_front.sh
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/root/.nvm/versions/node/v13.9.0/bin
export PATH
project_dir=/home/project
project_name=$1
echo $project_dir"/"$project_name
branch=$2

function gitPullCover(){
    project_name=$1
    branch=$2
    project_dir=$3
    self_path=$project_dir"/history/"$project_name;
    cp -rf $project_dir"/"$project_name $project_dir"/history/"
    history_path=$project_dir"/history/"$project_name
    covertimes=5;
    if [ ! -d $history_path ];then
      mkdir $history_path
      covertimes=20
    fi
    history_path=$self_path"_history"
    if [ ! -d $history_path ];then
      mkdir $history_path
    fi

    echo "覆盖"covertimes"版本"
    covertimes=5
    for vv in {5..1}
    do
        cd $self_path
        git checkout $branch
        git_hashcode=`git log -n $vv --pretty=format:"%H"`
        v2=0;
        for line in $git_hashcode
        do
            declare -i v2=$v2+1;
            if [ "$v2" -eq "$vv" ]
            then
                echo $line;
                git checkout $line
                git reset --hard
                cd ../
                echo "$self_path/* $history_path"
                cp -rf $self_path/* $history_path
            fi
        done
    done
    cd $self_path
    git checkout $branch
}

function gitPull(){
    cd $1
    echo `git log -n 1`
    git log -n 1
    git checkout .
    git pull origin $branch
}

function dockerReload(){
    cd $1"/src"
    docker-compose down && docker-compose up -d
}

gitPullCover $project_name $branch $project_dir

gitPull $project_dir"/"$project_name $branch
  • vim 后端laravel用到的发布文件 vim php_deploy_laravel.sh
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/root/.nvm/versions/node/v13.9.0/bin
export PATH
project_dir=/home/project/"$1"
echo $project_dir
branch=$2

function gitPull(){
    cd $1
    echo `git log -n 1`
    git log -n 1
    git checkout .
    git pull origin $2
}

gitPull $project_dir $branch
  • vim 后端hyperf框架用到的发布文件 vim php_deploy_hyperf.sh
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/root/.nvm/versions/node/v13.9.0/bin
export PATH
project_dir=/home/project/"$1"
echo $project_dir
branch=$2

function gitPull(){
    cd $1
    echo `git log -n 1`
    git log -n 1
    git checkout .
    git pull origin $branch
}

function dockerReload(){
    cd $1"/src"
    docker-compose down && docker-compose up -d
}

gitPull $project_dir

dockerReload $project_dir
  • 如果无法执行, 检查是否权限问题, 是否开启发布的用户的 sudo 的免密登录