Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_old_ip_remove #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions .githun/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 0 additions & 9 deletions conf/auth.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,3 @@
# }
# }

Authority {
Auth {
Mode write
}
Auth "#a complex password#" {
Mode admin
}
}

47 changes: 40 additions & 7 deletions src/ClusterServerPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -189,9 +217,13 @@ void ClusterServerPool::handleResponse(Handler* h, ConnectConnection* s, Request
return;
}
}
for (auto serv : mServPool) {
for (std::vector<Server*>::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) {
Expand Down Expand Up @@ -229,6 +261,7 @@ void ClusterServerPool::handleResponse(Handler* h, ConnectConnection* s, Request
g->remove(serv);
}
}
++it;
}
}

1 change: 1 addition & 0 deletions src/ClusterServerPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ClusterServerPool : public ServerPoolTmpl<ClusterServerPool>
{
return mServPool;
}
void removeServer(Server* srv);
private:
Server* getServer(Handler* h, Request* req, const String& key) const;
void refreshRequest(Handler* h);
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

int main(int argc, char* argv[])
{
printf("this is test ok!");
try {
Proxy p;
if (!p.init(argc, argv)) {
Expand Down