├── .github └── workflows │ └── gitee-repos-mirror.yml ├── .gitignore ├── README.md └── ssh ├── execFn.js ├── index.js └── sshServer.js /.github/workflows/gitee-repos-mirror.yml: -------------------------------------------------------------------------------- 1 | name: Sync To Gitee 2 | on: page_build 3 | jobs: 4 | sync: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: wearerequired/git-mirror-action@master 8 | env: 9 | SSH_PRIVATE_KEY: ${{ secrets.GITEE_PRIVATE_KEY }} 10 | with: 11 | source-repo: "git@github.com:CatsAndMice/b.git" 12 | destination-repo: "git@gitee.com:JsHai/Blog.git" 13 | - name: Build Gitee Pages 14 | uses: yanglbme/gitee-pages-action@main 15 | with: 16 | # 注意替换为你的 Gitee 用户名 17 | gitee-username: 13034833806 18 | # 注意在 Settings->Secrets 配置 GITEE_PASSWORD 19 | gitee-password: ${{ secrets.GITEE_PASSWORD }} 20 | # 注意替换为你的 Gitee 仓库,仓库名严格区分大小写,请准确填写,否则会出错 21 | gitee-repo: JsHai/Blog 22 | # 要部署的分支,默认是 master,若是其他分支,则需要指定(指定的分支必须存在) 23 | branch: main 24 | 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | docs/.vuepress/dist/ 4 | ssh/config.json 5 | ssh/server.xlsx 6 | # /dist 7 | .id 8 | dist.zip 9 | .git 10 | # local env files 11 | .env.local 12 | .env.*.local 13 | 14 | # Log files 15 | npm-debug.log* 16 | yarn-debug.log* 17 | yarn-error.log* 18 | pnpm-debug.log* 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | *.log 26 | 27 | # Editor directories and files 28 | .vscode 29 | *.suo 30 | *.ntvs* 31 | *.njsproj 32 | *.sln 33 | *.sw? 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 凌览的博客 2 | 3 | ## 公众号 4 | |微信(凌览本人)|公众号| 5 | |:----:|:----:| 6 | ||| 7 | |凌览|凌览社| 8 | 9 | ## 活跃社区 10 | * [掘金](https://juejin.cn/user/3350967174565198/posts) 11 | * [CSDN](https://blog.csdn.net/qq_45472813?type=blog) 12 | * [segmentfault](https://segmentfault.com/u/xuexishiwokuaile_612449e36bade) 13 | * [知乎](https://www.zhihu.com/people/25-32-14-8/posts) 14 | 15 | ## Node.js实战 16 | 1. Node.js操作Dom ,轻松hold住简单爬虫 17 | 2. 50+行代码搞定一行命令更新Npm包 18 | 3. 仿jsDoc写一个最简单的文档生成 19 | 4. 玩转nodeJs文件模块 20 | 5. 【Node.js】写一个数据自动整理成表格的脚本 21 | 6. 【Node.js】ssh2.js+Shell一套组合拳下来,一年要花2080分钟做的工作竟然节省到52分钟~ 22 | 7. Node.js搭建Https服务 23 | 8. [用Node.js吭哧吭哧撸一个运动主页](https://github.com/CatsAndMice/blog/issues/59) 24 | 9. [NodeServe:构建高效静态文件服务器的完美指南](https://github.com/CatsAndMice/blog/issues/61) 25 | 10. [Linux服务器上运行Puppeteer的Docker部署指南](https://github.com/CatsAndMice/blog/issues/66) 26 | 27 | [书籍分享&笔记](https://github.com/CatsAndMice/blog/issues?q=is%3Aopen+is%3Aissue+label%3A%E9%98%85%E8%AF%BB) 28 | 29 | ## 我的故事 30 | 1. 平淡无奇,2022年终总结 31 | 2. 写给五年后的自己 32 | 3. [2023年中总结|马马虎虎](https://github.com/CatsAndMice/blog/issues/55) 33 | 4. [谈谈我是怎么走上程序员这行的](https://github.com/CatsAndMice/blog/issues/67) 34 | 35 | 36 |
2024.01 37 | 38 | * [前端玩Word:Word文档解析成浏览器认识的HTML](https://linglan01.cn/post/69) 39 | * [【工具推荐】代码管理工具 CodeGist](https://linglan01.cn/post/68) 40 | * [盘点2023前端技术,谁才是当红炸子鸡](https://github.com/CatsAndMice/blog/issues/74) 41 | 42 |
43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ssh/execFn.js: -------------------------------------------------------------------------------- 1 | module.exports = (c = conn) => { 2 | return (command) => { 3 | return new Promise((resolve, reject) => { 4 | c.exec(command, (err, stream) => { 5 | if (err) { 6 | reject(err) 7 | return 8 | } 9 | let result = '' 10 | stream.on('close', () => { 11 | resolve(String(result)) 12 | }).on('data', (data) => { 13 | result += data 14 | }) 15 | }) 16 | }) 17 | } 18 | } -------------------------------------------------------------------------------- /ssh/index.js: -------------------------------------------------------------------------------- 1 | const { Client } = require('ssh2'); 2 | const configs = require('./config.json') 3 | const sshServer = require('./sshServer.js'); 4 | const fs = require('fs'); 5 | const path = require('path'); 6 | const nodeXlsx = require('node-xlsx') 7 | 8 | 9 | const promises = [] 10 | 11 | const tables = [ 12 | ['服务器ip', 'docker是否正常运行', 'docker远程访问', 'Docker日志是否有报错信息'] 13 | ] 14 | 15 | configs.forEach((config) => { 16 | const conn = new Client(); 17 | promises.push(sshServer(config, conn)) 18 | }) 19 | 20 | Promise.all(promises).then((data) => { 21 | data.forEach((d) => { 22 | if (Array.isArray(d)) { 23 | tables.push(d) 24 | } 25 | }) 26 | const buffer = nodeXlsx.build([{ name: '巡检', data: tables }]) 27 | const file = path.join(__dirname, '/server.xlsx') 28 | fs.writeFileSync(file, buffer, 'utf-8') 29 | console.log(file); 30 | }) 31 | 32 | -------------------------------------------------------------------------------- /ssh/sshServer.js: -------------------------------------------------------------------------------- 1 | const execFn = require('./execFn.js') 2 | const tinyAsyncPool = require('tiny-async-pool') 3 | const commandNum = 4 4 | 5 | async function asyncPoolAll(...args) { 6 | const results = []; 7 | for await (const result of tinyAsyncPool(...args)) { 8 | results.push(result); 9 | } 10 | return results; 11 | } 12 | 13 | const normal = '正常' 14 | 15 | module.exports = (config, conn) => { 16 | return new Promise((resolve, reject) => { 17 | const exec = execFn(conn) 18 | conn.on('ready', async (err) => { 19 | if (err) reject(err) 20 | console.log('连接成功'); 21 | const before = `echo "${config.password}" | sudo -S ` 22 | const rol = new Array(commandNum).fill(normal) 23 | rol[0] = config.host 24 | exec(before + 'systemctl status docker').then((content) => { 25 | const isRun = String(content).includes('active (running)') 26 | if (!isRun) { 27 | rol[1] = '异常' 28 | } 29 | }) 30 | 31 | // FIXME:该命令结果有问题,结果均返回空 32 | exec(before + 'docker info |grep -A 5 "WARNING"').then((content) => { 33 | if (content) { 34 | rol[2] = '异常' 35 | } 36 | }) 37 | const result = await exec(before + 'docker ps -a -q') 38 | const dockerIds = result.split('\n').filter(r => r) 39 | // 控制进程数为9,超出进程数报错 40 | await asyncPoolAll(3, dockerIds, async (id) => { 41 | const data = await exec(before + `docker logs --tail 200 ${id}`) 42 | if (data.includes('error')) { 43 | if (rol[3] === normal) { 44 | rol[3] = '' 45 | } 46 | rol[3] += `${id}异常;` 47 | return true 48 | } 49 | return false 50 | }); 51 | conn.end() 52 | resolve(rol) 53 | }).connect({ 54 | ...config, 55 | readyTimeout: 5000 56 | }); 57 | }) 58 | 59 | } --------------------------------------------------------------------------------