Skip to content

Commit

Permalink
doc: update docs/ansible.md & update CONTRIBUTING.md (#535)
Browse files Browse the repository at this point in the history
* doc: update ansible.md

* doc: update ansible.md 代码格式

* 增加十分钟同步的域名、增加自动部署脚本

* 优化部署文档:定时任务同步pages的内容

* 优化 git-down-pages.sh 脚本 到配置

* update  README.md

---------

Co-authored-by: 魏栋梁 <dongliang.wei@fujfu.com>
  • Loading branch information
nangongchengfeng and 魏栋梁 committed Feb 28, 2024
1 parent 20c2bfd commit 893391c
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 18 deletions.
120 changes: 120 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/)

感谢🙏

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ Quick Reference
[srebro.cn](https://ref.srebro.cn)<!--rehype:target=_blank&data-info=👆每天自动同步-->
[haah.net](https://ref.haah.net)<!--rehype:target=_blank&data-info=👆每天自动同步-->
[xiechengqi.top](https://ref.xiechengqi.top)<!--rehype:target=_blank&data-info=👆每天自动同步-->
[ownit.top](https://memo.ownit.top)<!--rehype:target=_blank&data-info=👆每十分钟自动同步-->
[666666.dev](https://cheat.666666.dev)<!--rehype:target=_blank&data-info=👆每天自动同步-->
[laoleng.vip](http://bbs.laoleng.vip/reference/)<!--rehype:target=_blank-->
[dbyun.net](https://www.dbyun.net/reference/index.html)<!--rehype:target=_blank-->
Expand Down Expand Up @@ -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 版。



<!--rehype:ignore:start-->
## License

MIT © [Kenny Wong](https://github.com/jaywcjlove)
<!--rehype:ignore:end-->
<!--rehype:ignore:end-->
35 changes: 18 additions & 17 deletions docs/ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,24 @@ $ ansible <host-pattern> [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的软件包安装和管理 | 安装<br />ansible all -m yum -a "name=httpd state=present"<br/>ansible all -m yum -a "name=httpd state=installed"<br />卸载<br />ansible all -m yum -a "name=httpd state=absent"<br/>ansible all -m yum -a "name=httpd state=removed" |
| service和systemd | 用于管理远程主机的服务 | ansible all -m systemd -a "name=httpd state=started enabled=yes"<br />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的软件包安装和管理 | `安装<br />ansible all -m yum -a "name=httpd state=present"<br/>ansible all -m yum -a "name=httpd state=installed"<br />卸载<br />ansible all -m yum -a "name=httpd state=absent"<br/>ansible all -m yum -a "name=httpd state=removed"` |
| service和systemd | 用于管理远程主机的服务 | `ansible all -m systemd -a "name=httpd state=started enabled=yes"<br />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'"` |

<!--rehype:className=style-list-->

Expand Down

0 comments on commit 893391c

Please sign in to comment.