From 893391cc3b5bc205c1a785d1e2400aa28f6fa4bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=97=E5=AE=AB=E4=B9=98=E9=A3=8E?= <46562911+nangongchengfeng@users.noreply.github.com> Date: Wed, 28 Feb 2024 23:58:09 +0800 Subject: [PATCH] doc: update docs/ansible.md & update CONTRIBUTING.md (#535) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * doc: update ansible.md * doc: update ansible.md 代码格式 * 增加十分钟同步的域名、增加自动部署脚本 * 优化部署文档:定时任务同步pages的内容 * 优化 git-down-pages.sh 脚本 到配置 * update README.md --------- Co-authored-by: 魏栋梁 --- CONTRIBUTING.md | 120 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 5 +- docs/ansible.md | 35 +++++++------- 3 files changed, 142 insertions(+), 18 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c001a85..e3aeb98 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -98,6 +98,125 @@ $ npm run start # 监听 md 文件编译输出 HTML $ git clone https://github.com/jaywcjlove/reference.git -b gh-pages ``` +**进击方式:** + +在Linux服务执行 ` git-down-pages.sh` [会根据线上pages的commit 和 本地 commit 比较。如果不一致才会同步更新,否则跳过] + +注意:请把脚本放在/opt/cron/ 目录下 + +```bash +vim git-down-pages.sh + +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +#author: 南宫乘风 + +DATA_DIR="/data" +REPO_URL="https://gitee.com/jaywcjlove/reference.git" +BRANCH="gh-pages" +MAX_BACKUPS=3 + +# 函数:备份旧版本 +backup_old_version() { + echo "备份旧版本..." + mv ../reference ../reference_backup_$(date +%Y%m%d%H%M%S) + if [ $? -eq 0 ]; then + echo "备份完成。" + remove_old_backups + else + echo "备份时出现错误。" + exit 1 + fi +} + +# 函数:删除多余备份,保留最近的三个 +remove_old_backups() { + echo "删除多余备份,保留最近的三个..." + ls -1d ../reference_backup_* | head -n -${MAX_BACKUPS} | xargs -r rm -r +} + +# 函数:拉取最新代码 +clone_latest_code() { + echo "拉取最新代码..." + git clone $REPO_URL -b $BRANCH + if [ $? -eq 0 ]; then + echo "拉取最新代码完成。" + else + echo "拉取最新代码时出现错误。" + exit 1 + fi +} + +# 检查是否存在 DATA_DIR 目录,不存在则创建 +if [ ! -d "$DATA_DIR" ]; then + echo "目录 $DATA_DIR 不存在,创建中..." + mkdir -p "$DATA_DIR" + if [ $? -eq 0 ]; then + echo "目录创建成功。" + else + echo "目录创建失败。" + exit 1 + fi +fi + + + +# 进入 /data 目录 +cd $DATA_DIR + +# 检查是否存在 reference 目录 +if [ -d "reference" ]; then + # 进入 reference 目录 + cd reference + + # 获取远程和本地的 commit 哈希值 + REMOTE_COMMIT=$(git ls-remote $REPO_URL $BRANCH | cut -f1) + LOCAL_COMMIT=$(git rev-parse HEAD) + + # 比较远程和本地的 commit + if [ "$REMOTE_COMMIT" == "$LOCAL_COMMIT" ]; then + echo "本地 'reference' 目录已经是最新版本,无需拉取。" + else + echo "本地 'reference' 目录不是最新版本,开始拉取最新代码..." + backup_old_version + clone_latest_code + fi +else + # 如果目录不存在,直接克隆 + clone_latest_code +fi + +echo "----------------------------------------------------------------------------" +endDate=`date +"%Y-%m-%d %H:%M:%S"` +echo "★[$endDate] Successful" +echo "----------------------------------------------------------------------------" + +``` + +```bash +定时任务 + 注意:请把脚本放在/opt/cron/ 目录下 (时间可以根据自己需求设定) + 下面案例:每十分钟同步线上的pages的内容 + crontab -e + */10 * * * * /opt/cron/git-down-pages.sh >> /opt/cron/git-down.log 2>&1 + + +NGINX 配置: + listen 80; + listen 443 ssl http2; + server_name xxx.xxx.top; #配置你的域名 + index index.php index.html index.htm default.php default.htm default.html; + root /data/reference; # 文件存放的位置 +``` + + + + + + + ### 方法二,使用 [docker](https://hub.docker.com/r/wcjiang/reference) 快捷部署 web 版 ```shell @@ -161,6 +280,7 @@ REF_LABEL=网站首页 - [quickreference.pages.dev](https://quickreference.pages.dev/) - [code05.com](https://reference.code05.com/) - [xhfun.cn](https://ref.xhfun.cn/) +- [ownit.top](https://memo.ownit.top/) 感谢🙏 diff --git a/README.md b/README.md index 5935010..e783848 100644 --- a/README.md +++ b/README.md @@ -641,6 +641,7 @@ Quick Reference [srebro.cn](https://ref.srebro.cn) [haah.net](https://ref.haah.net) [xiechengqi.top](https://ref.xiechengqi.top) +[ownit.top](https://memo.ownit.top) [666666.dev](https://cheat.666666.dev) [laoleng.vip](http://bbs.laoleng.vip/reference/) [dbyun.net](https://www.dbyun.net/reference/index.html) @@ -698,8 +699,10 @@ Quick Reference 如果你有资源,可以很方便[部署 web 版](https://github.com/jaywcjlove/reference/issues/102#issue-1451649637),这非常简单,只需要克隆 [gh-pages](https://github.com/jaywcjlove/reference/tree/gh-pages) 分支代码到你的静态服务就可以了,还可以使用 [docker](https://hub.docker.com/r/wcjiang/reference) 快捷部署 web 版。 + + ## License MIT © [Kenny Wong](https://github.com/jaywcjlove) - + \ No newline at end of file diff --git a/docs/ansible.md b/docs/ansible.md index 5bc55c6..be56bb5 100644 --- a/docs/ansible.md +++ b/docs/ansible.md @@ -248,23 +248,24 @@ $ ansible [options] # 标准使用方式 | :- | - | - | | ---------------- | ------------------------------------------------ | ------------------------------------------------------------ | -| ping | 检查指定节点机器是否还能连通 | ansible all -m ping | -| command | 用于在各受控端节点运行指定的命令 | ansible all -m command -a 'hostname' | -| shell | shell模块可以特殊字符,而command是不支持 | ansible all -m shell -a 'hostname && date' | -| hostname | 修改远程受控节点的主机名的模块 | ansible -i /opt/hosts xx -m hostname -a 'name=ansible-client-199' | -| copy | 在远程主机执行复制操作文件 | ansible all -m copy -a 'src=/etc/hosts dest=/opt/hosts backup=yes' | -| fetch | 从远程主机获取文件到管理节点,但是不支持目录操作 | ansible all -m fetch -a "src=/etc/yum.repos.d/epel.repo dest=/usr/local/src" | -| script | 管理端一个脚本,然后在远程服务器上执行 | ansible all -m script -a '/root/time.sh' | -| file | 主要用于远程主机上的文件和目录操作 | ansible all -m file -a "path=/root/rsync.password mode=600 state=touch" | -| cron | 管理执行任务计划模块(增删改查) | ansible all -m cron -a "name='test a job' user=root job='/bin/sh /server/scripts/test.sh' minute=* hour=* day=* month=* weekday=*" | -| yum | RedHat和CentOS的软件包安装和管理 | 安装
ansible all -m yum -a "name=httpd state=present"
ansible all -m yum -a "name=httpd state=installed"
卸载
ansible all -m yum -a "name=httpd state=absent"
ansible all -m yum -a "name=httpd state=removed" | -| service和systemd | 用于管理远程主机的服务 | ansible all -m systemd -a "name=httpd state=started enabled=yes"
ansible all -m systemd -a "name=httpd state=restarted" | -| user | useradd, userdel, usermod | ansible all -m user -a 'name=haha remove=no state=absent' | -| group | groupadd, groupdel, groupmod | ansible all -m group -a 'name=mygroup state=absent' | -| setup | 可收集远程主机的facts变量的信息 | ansible all -m setup -a 'filter=ansible_default_ipv4' | -| authorized_key | 为特定的用户账号添加或删除 SSH authorized keys | ansible all -m authorized_key -a "user=root key='{{lookup('file','/root/.ssh/id_rsa.pub')}}' path=/root/.ssh/authorized_keys manage_dir=no" | -| replace | 和 sed 命令比较类似,用于正则匹配和替换 | ansible all -m replace -a "path=/etc/fstab regexp=^(UUID.*) replace='#\1'" | -| lineinfile | 正则匹配,更改某个关键参数值 | ansible all -m lineinfile -a "path=/etc/selinux/config regexp='^SELINUX=' line='SELINUX=disabled'" | + +| ping | 检查指定节点机器是否还能连通 | `ansible all -m ping` | +| command | 用于在各受控端节点运行指定的命令 | `ansible all -m command -a 'hostname'` | +| shell | shell模块可以特殊字符,而command是不支持 | `ansible all -m shell -a 'hostname && date'` | +| hostname | 修改远程受控节点的主机名的模块 | `ansible -i /opt/hosts xx -m hostname -a 'name=ansible-client-199'` | +| copy | 在远程主机执行复制操作文件 | `ansible all -m copy -a 'src=/etc/hosts dest=/opt/hosts backup=yes'` | +| fetch | 从远程主机获取文件到管理节点,但是不支持目录操作 | `ansible all -m fetch -a "src=/etc/yum.repos.d/epel.repo dest=/usr/local/src"` | +| script | 管理端一个脚本,然后在远程服务器上执行 | `ansible all -m script -a '/root/time.sh'` | +| file | 主要用于远程主机上的文件和目录操作 | `ansible all -m file -a "path=/root/rsync.password mode=600 state=touch"` | +| cron | 管理执行任务计划模块(增删改查) | `ansible all -m cron -a "name='test a job' user=root job='/bin/sh /server/scripts/test.sh' minute=* hour=* day=* month=* weekday=*"` | +| yum | RedHat和CentOS的软件包安装和管理 | `安装
ansible all -m yum -a "name=httpd state=present"
ansible all -m yum -a "name=httpd state=installed"
卸载
ansible all -m yum -a "name=httpd state=absent"
ansible all -m yum -a "name=httpd state=removed"` | +| service和systemd | 用于管理远程主机的服务 | `ansible all -m systemd -a "name=httpd state=started enabled=yes"
ansible all -m systemd -a "name=httpd state=restarted"` | +| user | useradd, userdel, usermod | `ansible all -m user -a 'name=haha remove=no state=absent'` | +| group | groupadd, groupdel, groupmod | `ansible all -m group -a 'name=mygroup state=absent'` | +| setup | 可收集远程主机的facts变量的信息 | `ansible all -m setup -a 'filter=ansible_default_ipv4'` | +| authorized_key | 为特定的用户账号添加或删除 SSH authorized keys | `ansible all -m authorized_key -a "user=root key='{{lookup('file','/root/.ssh/id_rsa.pub')}}' path=/root/.ssh/authorized_keys manage_dir=no"` | +| replace | 和 sed 命令比较类似,用于正则匹配和替换 | `ansible all -m replace -a "path=/etc/fstab regexp=^(UUID.*) replace='#\1'"` | +| lineinfile | 正则匹配,更改某个关键参数值 | `ansible all -m lineinfile -a "path=/etc/selinux/config regexp='^SELINUX=' line='SELINUX=disabled'"` |