From 9e399d02d5c738c6178ae7f2227d16aeb5f07406 Mon Sep 17 00:00:00 2001 From: liupeng18 Date: Thu, 30 Sep 2021 16:41:41 +0800 Subject: [PATCH 1/2] fix_old_ip_remove --- .githun/workflows/main.yml | 60 ++++++++++++++++++++++++++++++++++++++ Makefile | 6 ++-- conf/auth.conf | 9 ------ src/ClusterServerPool.cpp | 47 ++++++++++++++++++++++++----- src/ClusterServerPool.h | 1 + src/main.cpp | 1 + 6 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 .githun/workflows/main.yml diff --git a/.githun/workflows/main.yml b/.githun/workflows/main.yml new file mode 100644 index 0000000..ad3b8bc --- /dev/null +++ b/.githun/workflows/main.yml @@ -0,0 +1,60 @@ +name: Publish And Deploy Demo # 自动部署的名称 +on: + push: + master: # 当我们提交代码为tag 是以'v'开头的时候才会触发自动部署到服务端 如 git push tag v0.1.0 + +jobs: + build-and-deploy: + runs-on: ubuntu-latest # 运行环境,告诉它运行在什么环境 + steps: # 步骤 + + # 第一步:下载源码(CI/CD拉取代码到自己的本地) + - name: Checkout + uses: actions/checkout@master + + # 第二步:打包构建 + - name: Build + uses: actions/setup-make@master + - run: make # 安装第三方包 + - run: tar -zcvf release.tgz conf src/predixy + # 把.nuxt、nuxt.config.js等文件,打包压缩为release.tgz + + # 第三步:发布 Release + - name: Create Release # 创建Release,可以在仓库看到一个个版本 + id: create_release + uses: actions/create-release@master + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} # 之前GitHub添加的Token + with: + tag_name: ${{ github.ref }} # (tag)标签名称 + release_name: Release ${{ github.ref }} + draft: false # 是否是草稿 + prerelease: false # 是否是预发布 + + # 第四步:上传构建结果到 Release(把打包的tgz上传到Release) + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@master + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # 上传地址,通过创建Release获取到的 + asset_path: ./release.tgz # 要上传文件 + asset_name: release.tgz # 上传后的文件名 + asset_content_type: application/x-tgz + + # 第五步:部署到服务器 + - name: Deploy + uses: appleboy/ssh-action@master # 使用ssh链接服务器 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + port: ${{ secrets.PORT }} + script: | # 执行命令(运行到服务器)cd:要确保服务器有这个目录; wget:下载上一步的release到服务器; tar:解压; 安装依赖;启动服务 + cd /root/realworld-nuxtjs + wget https://github.com/YuYun95/realworld-nuxtjs/releases/latest/download/release.tgz -O release.tgz + tar zxvf release.tgz + npm install --production + pm2 reload pm2.config.json + diff --git a/Makefile b/Makefile index ed82317..5dfc90d 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,10 @@ else ifeq ($(plt), OpenBSD) endif default: - @$(make) -C src -f Makefile + @$(make) -C src -f Makefile debug: - @$(make) -C src -f Makefile debug + @$(make) -C src -f Makefile debug clean: - @$(make) -C src -f Makefile clean + @$(make) -C src -f Makefile clean diff --git a/conf/auth.conf b/conf/auth.conf index 169cf0e..b43b43f 100644 --- a/conf/auth.conf +++ b/conf/auth.conf @@ -60,12 +60,3 @@ # } # } -Authority { - Auth { - Mode write - } - Auth "#a complex password#" { - Mode admin - } -} - diff --git a/src/ClusterServerPool.cpp b/src/ClusterServerPool.cpp index 35591d2..1351c76 100644 --- a/src/ClusterServerPool.cpp +++ b/src/ClusterServerPool.cpp @@ -85,22 +85,50 @@ void ClusterServerPool::refreshRequest(Handler* h) RequestPtr req = RequestAlloc::create(Request::ClusterNodes); h->handleRequest(req); } - +void ClusterServerPool::removeServer(Server* serv) { + if (nullptr == serv) return; + logNotice("redis cluster delete old server %s %s %s %s %s", + serv->name().data(), + serv->addr().data(), + serv->roleStr(), + serv->masterName().data(), + serv->dcName().data()); + ServerGroup* g = getGroup(serv->name()); + if (serv->group() && serv->group() != g) { + serv->group()->remove(serv); + } + auto mapServ = mServs.find(serv->addr()); + if (mapServ != mServs.end()) + { + mServs.erase(mapServ); + } + delete serv; +} void ClusterServerPool::handleResponse(Handler* h, ConnectConnection* s, Request* req, Response* res) { ClusterNodesParser p; p.set(res->body()); for (auto serv : mServPool) { serv->setUpdating(true); + logNotice("redis old cluster nodes get node %s %s %s %s", + serv->name().data(), + serv->addr().data(), + serv->roleStr(), + serv->masterName().data()); } while (true) { ClusterNodesParser::Status st = p.parse(); if (st == ClusterNodesParser::Node) { - logDebug("redis cluster update parse node %s %s %s %s", - p.nodeId().data(), - p.addr().data(), - p.flags().data(), - p.master().data()); + logNotice("redis update cluster nodes get node %s %s %s %s", + p.nodeId().data(), + p.addr().data(), + p.flags().data(), + p.master().data()); + // logDebug("redis cluster update parse node %s %s %s %s", + // p.nodeId().data(), + // p.addr().data(), + // p.flags().data(), + // p.master().data()); if (p.addr().empty()) { logWarn("redis cluster nodes get node invalid %s %s %s %s", p.nodeId().data(), @@ -189,9 +217,13 @@ void ClusterServerPool::handleResponse(Handler* h, ConnectConnection* s, Request return; } } - for (auto serv : mServPool) { + for (std::vector::iterator it = mServPool.begin(); it != mServPool.end();) { + //for (auto serv : mServPool) { + auto serv = *it; if (serv->updating()) { serv->setUpdating(false); + it = mServPool.erase(it); //删除不在集群中节点 + removeServer(serv); continue; } if (serv->role() == Server::Master) { @@ -229,6 +261,7 @@ void ClusterServerPool::handleResponse(Handler* h, ConnectConnection* s, Request g->remove(serv); } } + ++it; } } diff --git a/src/ClusterServerPool.h b/src/ClusterServerPool.h index af9e27d..c6536a1 100644 --- a/src/ClusterServerPool.h +++ b/src/ClusterServerPool.h @@ -25,6 +25,7 @@ class ClusterServerPool : public ServerPoolTmpl { return mServPool; } + void removeServer(Server* srv); private: Server* getServer(Handler* h, Request* req, const String& key) const; void refreshRequest(Handler* h); diff --git a/src/main.cpp b/src/main.cpp index 5bade3f..c5f2eeb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ int main(int argc, char* argv[]) { + printf("this is test ok!"); try { Proxy p; if (!p.init(argc, argv)) { From 758b460e135796b51eb5382bad94efcc3797f297 Mon Sep 17 00:00:00 2001 From: liupeng2017 <33984426+liupeng2017@users.noreply.github.com> Date: Thu, 30 Sep 2021 18:20:43 +0800 Subject: [PATCH 2/2] Create main.yml --- .github/workflows/main.yml | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..8ef24cd --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,65 @@ +name: Publish And Deploy Demo # 自动部署的名称 +#on: +# push: +# tag: # 当我们提交代码为tag 是以'v'开头的时候才会触发自动部署到服务端 如 git push tag v0.1.0 +# -v: "v*" +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build-and-deploy: + runs-on: ubuntu-latest # 运行环境,告诉它运行在什么环境 + steps: # 步骤 + + # 第一步:下载源码(CI/CD拉取代码到自己的本地) + - name: Checkout + uses: actions/checkout@master + + # 第二步:打包构建 + - name: Build + uses: actions/setup-make@master + - run: make # 安装第三方包 + - run: tar -zcvf release.tgz conf src/predixy + # 把.nuxt、nuxt.config.js等文件,打包压缩为release.tgz + + # 第三步:发布 Release + - name: Create Release # 创建Release,可以在仓库看到一个个版本 + id: create_release + uses: actions/create-release@master + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} # 之前GitHub添加的Token + with: + tag_name: ${{ github.ref }} # (tag)标签名称 + release_name: Release ${{ github.ref }} + draft: false # 是否是草稿 + prerelease: false # 是否是预发布 + + # 第四步:上传构建结果到 Release(把打包的tgz上传到Release) + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@master + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # 上传地址,通过创建Release获取到的 + asset_path: ./release.tgz # 要上传文件 + asset_name: release.tgz # 上传后的文件名 + asset_content_type: application/x-tgz + + # 第五步:部署到服务器 + - name: Deploy + uses: appleboy/ssh-action@master # 使用ssh链接服务器 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + port: ${{ secrets.PORT }} + script: | # 执行命令(运行到服务器)cd:要确保服务器有这个目录; wget:下载上一步的release到服务器; tar:解压; 安装依赖;启动服务 + cd /root/realworld-nuxtjs + wget https://github.com/YuYun95/realworld-nuxtjs/releases/latest/download/release.tgz -O release.tgz + tar zxvf release.tgz + npm install --production + pm2 reload pm2.config.json