整理笔记目录 完善gogcli文档

This commit is contained in:
billyshen
2026-03-24 09:52:46 +08:00
parent e862fb7daa
commit e3c69a805b
76 changed files with 84 additions and 6081 deletions

View File

@@ -231,7 +231,7 @@ remotePort = 15678
### 基本信息
- **FRP目录**: `/opt/frp/frp_0.65.0_linux_amd64`
- **配置文件**: `frpc.toml`
- **运行用户**: root (通过 tmux 管理)
- **运行用户**: root (通过 systemd 管理)
### 代理配置列表
@@ -285,7 +285,7 @@ remotePort = 18889
### 基本信息
- **FRP目录**: `/opt/frp/frp_0.65.0_linux_amd64`
- **配置文件**: `frpc.toml`
- **运行用户**: root
- **运行用户**: root (通过 systemd 管理)
### 代理配置列表

View File

@@ -0,0 +1,275 @@
#gog #gog-cli #macos
本文档记录在 macOS 系统上安装和配置 gog CLI 的完整步骤,以便通过命令行管理 Google WorkspaceGmail、Google Calendar、Google Drive、Google Contacts、Google Docs、Google Sheets
## 目录
```table-of-contents
```
---
## 前置条件
- macOS 系统
- Homebrew 已安装
- Google 账号
---
## 安装步骤
### 1. 安装 gog CLI
使用 Homebrew 安装 gog CLI
```bash
brew install steipete/tap/gogcli
```
验证安装:
```bash
which gog
# 输出: /opt/homebrew/bin/gog
```
---
## 配置 OAuth 凭证
### 1. 在 Google Cloud Console 创建 OAuth 凭证
1. 打开 [Google Cloud Console - Credentials](https://console.cloud.google.com/apis/credentials)
2. 点击 **「创建凭证」** → 选择 **「OAuth 客户端 ID」**
3. 应用类型选择 **「桌面应用」**
4. 命名(例如:`gogcli`
5. 点击 **「创建」**
6. 点击 **「下载 JSON」**,得到 `credentials.json` 文件
### 2. 移动凭证文件到 gogcli 配置目录
- 创建 gogcli 配置目录(如果不存在):
```bash
mkdir -p "/Users/weishen/Library/Application Support/gogcli"
```
- 移动下载的凭证文件:
```bash
mv ~/Downloads/credentials.json "/Users/weishen/Library/Application Support/gogcli/credentials.json"
```
- 使用命令指定凭证路径:
```bash
gog auth credentials /Users/weishen/Library/Application\ Support/gogcli/credentials.json
```
---
## 解除 Google 安全限制
### 问题描述
首次授权时Google 会显示以下错误:
> 此应用未经 Google 验证
> 此应用请求访问您 Google 账号中的敏感信息。在开发者让该应用通过 Google 验证之前,请勿使用该应用。
### 解决方法:添加测试用户
1. 打开 [Google Cloud Console - Credentials](https://console.cloud.google.com/apis/credentials)
2. 找到你创建的 OAuth 客户端ID的项目点击进入详情
3. 找到 **「目标对象」**
4. 找到 **「测试用户」** 部分
5. 点击 **「添加用户」**
6. 输入你的 Google 邮箱:`ishenwei@gmail.com`
7. 保存
添加测试用户后,重新运行授权命令即可:
```bash
gog auth add ishenwei@gmail.com --services gmail,calendar,drive,contacts,docs,sheets
```
这会打开浏览器让你登录 Google 账号并授权。
---
## 启用Google API 服务(以 Gmail API 为例)
### 1. 核心原理
Google API 调用需要满足两层条件:
| 层级 | 控制内容 |
| -------------- | ---------- |
| OAuth | 用户身份 |
| API Enablement | 是否允许调用 API |
👉 即使 OAuth 成功,如果 API 未启用:
也会报错:
403 accessNotConfigured
### 2. 典型错误示例
Gmail API has not been used in project XXX
👉 表示:
该 Project 未启用 Gmail API
### 3. 操作步骤
#### Step 1进入 API 页面
Google Cloud Console
→ APIs & Services
→ Library
#### Step 2搜索 API
例如:
Gmail API
#### Step 3启用
Enable
#### Step 4等待生效
30 秒 ~ 2 分钟(有延迟)
#### Step 5重新授权关键
gog auth revoke
gog auth login
👉 原因:
旧 token 不包含新权限
---
## 验证配置
### 1. 查看已授权的账号
```bash
gog auth list
```
- 正确结果
```
weishen@WeideMac-mini ~ % gog auth list
ishenwei@gmail.com default calendar,contacts,docs,drive,gmail,sheets 2026-03-24T01:29:14Z oauth
```
### 2. 测试 Gmail
```bash
gog gmail search "newer_than:1d" --max 5
```
- 正确结果:
```
weishen@WeideMac-mini ~ % gog auth list
ishenwei@gmail.com default calendar,contacts,docs,drive,gmail,sheets 2026-03-24T01:29:14Z oauth
```
### 3. 测试 Calendar
```bash
gog calendar events primary --from 2026-01-01 --to 2026-12-31
```
---
## 常用命令
### Gmail
| 功能 | 命令 |
|------|------|
| 搜索邮件 | `gog gmail search 'newer_than:7d' --max 10` |
| 发送邮件 | `gog gmail send --to a@b.com --subject "Hi" --body "Hello"` |
| 发送邮件(多行) | `gog gmail send --to a@b.com --subject "Hi" --body-file ./message.txt` |
| 创建草稿 | `gog gmail drafts create --to a@b.com --subject "Hi" --body-file ./message.txt` |
| 发送草稿 | `gog gmail drafts send <draftId>` |
### Calendar
| 功能 | 命令 |
|------|------|
| 查看事件 | `gog calendar events <calendarId> --from <iso> --to <iso>` |
| 创建事件 | `gog calendar create <calendarId> --summary "Title" --from <iso> --to <iso>` |
| 查看颜色 | `gog calendar colors` |
### Drive
| 功能 | 命令 |
|------|------|
| 搜索文件 | `gog drive search "query" --max 10` |
### Contacts
| 功能 | 命令 |
|------|------|
| 列出联系人 | `gog contacts list --max 20` |
### Sheets
| 功能 | 命令 |
|------|------|
| 获取数据 | `gog sheets get <sheetId> "Tab!A1:D10" --json` |
| 更新数据 | `gog sheets update <sheetId> "Tab!A1:B2" --values-json '[["A","B"],["1","2"]]' --input USER_ENTERED` |
### Docs
| 功能 | 命令 |
|------|------|
| 导出文档 | `gog docs export <docId> --format txt --out /tmp/doc.txt` |
| 查看内容 | `gog docs cat <docId>` |
---
## 故障排除
### 凭证文件路径错误
确保凭证文件在以下位置:
```
/Users/weishen/Library/Application Support/gogcli/credentials.json
```
### 需要重新授权
删除现有授权并重新授权:
```bash
gog auth remove ishenwei@gmail.com
gog auth add ishenwei@gmail.com --services gmail,calendar,drive,contacts,docs,sheets
```
### 设置默认账号
避免每次重复指定账号:
```
cd ~
nano .zshrc
```
在.zshrc中添加以下设定
```bash
export GOG_ACCOUNT=ishenwei@gmail.com
```
保存生效
```
source ~/.zshrc
```
---
## 参考链接
- gog 官网: https://gogcli.sh
- gog GitHub: https://github.com/steipete/gogcli
- Google Cloud Console: https://console.cloud.google.com/
---
*文档创建日期: 2026-03-15*
*最后更新: 2026-03-15*

View File

@@ -0,0 +1,368 @@
#ubuntu #openclaw #install #uninstall
```table-of-contents
```
## 环境概述
- 系统Ubuntu 20.04 / 22.04
- OpenClaw 安装方式npm 用户本地全局安装openclaw & clawhub (注意不要用root user安装)
```
npm install -g openclaw clawhub
```
- 用户路径示例:
```bash
/home/shenwei/.npm-global/bin/openclaw
```
- 默认配置目录:
```bash
/home/shenwei/.openclaw
```
- 用户级 systemd 服务目录:
```bash
/home/shenwei/.config/systemd/user/openclaw-gateway.service
```
---
## 卸载旧版本 OpenClaw
1. **停止正在运行的进程 / 服务**
```bash
# 查找进程
ps aux | grep openclaw
# 如果有 systemd 用户服务
systemctl --user stop openclaw
systemctl --user disable openclaw
```
2. **卸载 npm 安装的 OpenClaw**
```bash
# 全局卸载
sudo npm uninstall -g openclaw clawhub
# 或者局部卸载
npm uninstall openclaw clawhub
```
3. **删除用户配置目录**
```bash
rm -rf /home/shenwei/.openclaw # 普通用户
sudo rm -rf /root/.openclaw # root 用户(如果曾用 sudo 运行)
sudo rm -rf /opt/openclaw # 如果之前手动统一过目录
```
4. **清理残留 npm 包**
```bash
npm list -g --depth=0 | grep openclaw
npm list -g --depth=0 | grep clawhub
```
如有残留再执行 `npm uninstall -g <package>`。
---
## 安装 OpenClaw
### 方法 A通过 npm 安装(推荐)
```bash
# 确保 npm 更新
npm install -g npm
# 全局安装 OpenClaw
npm install -g openclaw clawhub
```
---
## 配置 PATH让 OpenClaw 在任意位置可执行
1. 临时生效(仅当前终端):
```bash
export PATH=$HOME/.npm-global/bin:$PATH
```
2. 永久生效(推荐):
- 编辑 shell 配置文件 `~/.bashrc` 或 `~/.zshrc`,添加:
```bash
export PATH=$HOME/.npm-global/bin:$PATH
```
- 刷新配置:
```bash
source ~/.bashrc # bash
source ~/.zshrc # zsh
```
- 验证:
```bash
which openclaw
openclaw --version
```
---
## 用户级 systemd 服务管理OpenClaw Gateway
安装 Gateway 后会生成服务文件:
```bash
/home/shenwei/.config/systemd/user/openclaw-gateway.service
```
``` bash
[Unit]
Description=OpenClaw Gateway (v2026.3.13)
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/bin/node /home/shenwei/.npm-global/lib/node_modules/openclaw/dist/index.js gateway --port 18789
Restart=always
RestartSec=5
TimeoutStopSec=30
TimeoutStartSec=30
SuccessExitStatus=0 143
KillMode=control-group
Environment=HOME=/home/shenwei
Environment=TMPDIR=/tmp
Environment=HTTP_PROXY=http://127.0.0.1:10808
Environment=HTTPS_PROXY=http://127.0.0.1:10808
Environment=PATH=/home/shenwei/.local/bin:/home/shenwei/.npm-global/bin:/home/shenwei/bin:/home/shenwei/.volta/bin:/home/shenwei/.asdf/shims:/home/shenwei/.bun/bin:/>
Environment=OPENCLAW_GATEWAY_PORT=18789
Environment=OPENCLAW_SYSTEMD_UNIT=openclaw-gateway.service
Environment="OPENCLAW_WINDOWS_TASK_NAME=OpenClaw Gateway"
Environment=OPENCLAW_SERVICE_MARKER=openclaw
Environment=OPENCLAW_SERVICE_KIND=gateway
Environment=OPENCLAW_SERVICE_VERSION=2026.3.13
[Install]
WantedBy=default.target
```
查看日志
```
# 查看最近 50 行
journalctl --user -u openclaw-gateway -n 50 --no-pager
# 实时跟踪日志
journalctl --user -u openclaw-gateway -f
# 查看今天的所有日志
journalctl --user -u openclaw-gateway --since today
```
### 常用管理命令
| 操作 | 命令 |
| --------------------------- | ------------------------------------------- |
| 启动 Gateway | `systemctl --user start openclaw-gateway` |
| 停止 Gateway | `systemctl --user stop openclaw-gateway` |
| 重启 Gateway | `systemctl --user restart openclaw-gateway` |
| 查看状态 | `systemctl --user status openclaw-gateway` |
| 开机自启 | `systemctl --user enable openclaw-gateway` |
| 取消开机自启 | `systemctl --user disable openclaw-gateway` |
| 刷新 systemd 配置(修改 service 后) | `systemctl --user daemon-reload` |
> ⚠️ 用户级服务不需要 sudo安全且方便。
---
## 多用户环境与避免重复环境
- OpenClaw 配置目录默认跟随 `$HOME`
|用户|配置目录|
|---|---|
|shenwei|`/home/shenwei/.openclaw`|
|root|`/root/.openclaw`|
- **原因**Linux 用户隔离机制,不同用户运行 OpenClaw 会生成独立目录。
- **注意**
- 不要用 root 启动 OpenClaw避免权限混乱
- 统一使用普通用户安装和运行
- 可通过 `--workdir /opt/openclaw` 指定统一目录
---
## 常用命令总结
| 命令 | 功能 |
| --------------------------------------------------------------------- | ------------- |
| `openclaw onboard` | 初始化新环境、设置工作目录 |
| `openclaw --version` | 查看版本 |
| `openclaw agent list` | 列出所有 agent |
| `openclaw agent create --name <agent_name> --message "<description>"` | 创建新的 agent |
| `openclaw agent delete <agent_name>` | 删除 agent |
| `openclaw skill install <skill_name>` | 安装技能 |
| `openclaw skill update <skill_name>` | 更新技能 |
| `openclaw skill list` | 查看已安装技能 |
| `openclaw memory list` | 查看记忆数据 |
| `openclaw workspace list` | 查看工作空间 |
| | |
| | |
---
## 创建 Agent 与绑定 Telegram Bot
1. **创建 agent**
```
openclaw agents add <agentname> --non-interactive --workspace /home/shenwei/.openclaw/workspace-agent-<agentname> --model MiniMax-M2.5
```
举例:
```bash
openclaw agents add yunce --non-interactive --workspace /home/shenwei/.openclaw/workspace-agent-yunce --model MiniMax-M2.5
```
2. **添加Telegram 账号**
```
# 添加 Telegram 账号
openclaw channels add --channel telegram --account <账号名> --token <BotToken>
```
举例
```
openclaw channels add --channel telegram --account yunhan --token 8588117769:AAFxswhHgCdBor2EOa-2oChDpI-DADRt0tQ
```
3. **查看 agent 列表**
```bash
openclaw agents list
```
3. **绑定 Bot**
```
# 绑定 agent 到 Telegram 账号
openclaw agents bind --agent <agent_id> --bind telegram:<account_name>
```
举例
```
openclaw agents bind --agent yunhan --bind telegram:yunhan
```
- 配置完成后重启 Gateway
```bash
systemctl --user restart openclaw-gateway
```
- Telegram 多 Agent 建议:
- 一个 bot → n8n 路由 → 多 agent
- 避免每个 agent 都创建独立 bot每个账号最多 20 个 bot
- 用命令或路径路由区分不同 agent 功能
---
## 删除Agent
1. **删除 agent**
```
openclaw agents delete <agent_name> --force
```
2. **删除bot**
```
# 删除 Telegram 账号
openclaw channels remove --channel telegram --account <account_name> --delete
```
## 注意事项与避免的坑
1. **避免使用 root 运行**
- root 会生成 `/root/.openclaw`,和普通用户环境冲突
- 权限问题可能导致 agent 无法访问工作空间
2. **避免重复 PATH 或多版本冲突**
- 如果 npm 本地 bin 不在 PATH会导致命令找不到
- 如果 PATH 里还有旧版本系统全局安装路径,可能会调用错误版本
3. **用户级 systemd 服务管理**
- 修改 service 后必须执行 `systemctl --user daemon-reload`
- 避免 sudo 启动服务,保证文件权限正确
4. **Telegram Bot 限制**
- 每个账号最多创建 20 个 botPremium 账号可能 40 个)
- 多 agent 架构建议一个 bot → n8n → 多 agent 路由
5. **统一工作目录**
- 推荐 `/home/shenwei/.openclaw` 或 `/opt/openclaw`
- 方便多服务器或多 agent 管理
6. **升级和维护**
- 升级前先备份 `.openclaw` 下的 workspace、skills、memory
- 使用 npm 全局安装可直接 `npm install -g openclaw@latest`
---
### 参考架构示意
```
Telegram Bot
n8n Router
OpenClaw Agents
├─ 星枢(调度)
├─ 星曜IT管家
├─ 星辉(个人助理)
└─ 云瀚(监控)
```
### Bot & Agent 命名
#### 星
```
openclaw channels add --channel telegram --account xingshu --token 8787024183:AAG1M5tfSHj6Z0gMv3vvCZel2FOIX-0x8ZI
openclaw channels add --channel telegram --account xingyao --token 8414432613:AAG9hvKfILGSsbc1EMEZW1QVym9Quc5aHWk
openclaw channels add --channel telegram --account xinghui --token 8709222939:AAEfvZrvvU5vZFsmacsR5nmpkJ2Jb5JgfRg
```
| 服务器 | 角色 | Bot Name | Bot Key | Agent Id | Telegram User ID |
| ------- | --- | ---------------------------- | ---------------------------------------------- | -------- | ---------------- |
| macmini | 星枢 | @shenwei_macmini_xingshu_bot | 8787024183:AAG1M5tfSHj6Z0gMv3vvCZel2FOIX-0x8ZI | main | 5038825565 |
| macmini | 星曜 | @shenwei_macmini_xingyao_bot | 8414432613:AAG9hvKfILGSsbc1EMEZW1QVym9Quc5aHWk | xingyao | 5038825565 |
| macmini | 星辉 | @shenwei_macmini_xinghui_bot | 8709222939:AAEfvZrvvU5vZFsmacsR5nmpkJ2Jb5JgfRg | xinghui | 5038825565 |
| | | | | | |
#### 云
```
openclaw channels add --channel telegram --account yunhan --token 8588117769:AAFxswhHgCdBor2EOa-2oChDpI-DADRt0tQ
openclaw channels add --channel telegram --account yunce --token 8791231082:AAFKPfTPy3LshybWUJ0joBkz3Th3mwYQOnc
openclaw channels add --channel telegram --account yunjiang --token 8727937702:AAGw3WGPI1j5rSD97wap6h9EGqVpDEMdjLU
openclaw channels add --channel telegram --account yunzhi --token 8639619464:AAEI35Dnt-9PQ8y4Du_ToxVhwUBUa5kpLjU
```
| 服务器 | 角色 | Bot Name | Bot Key | Agent 名称 | Telegram User ID |
| ------- | --- | ----------------------------- | ---------------------------------------------- | -------- | ---------------- |
| ubuntu2 | 云瀚 | @shenwei_ubuntu2_yunhan_bot | 8588117769:AAFxswhHgCdBor2EOa-2oChDpI-DADRt0tQ | yunhan | 5038825565 |
| ubuntu2 | 云策 | @shenwei_ubuntu2_yunce_bot | 8791231082:AAFKPfTPy3LshybWUJ0joBkz3Th3mwYQOnc | yunce | 5038825565 |
| ubuntu2 | 云匠 | @shenwei_ubuntu2_yunjiang_bot | 8727937702:AAGw3WGPI1j5rSD97wap6h9EGqVpDEMdjLU | yunjiang | 5038825565 |
| ubuntu2 | 云织 | @shenwei_ubuntu2_yunzhi_bot | 8639619464:AAEI35Dnt-9PQ8y4Du_ToxVhwUBUa5kpLjU | yunzhi | 5038825565 |
#### 风
```
openclaw channels add --channel telegram --account fengheng --token
openclaw channels add --channel telegram --account fengchi --token
openclaw channels add --channel telegram --account fengji --token
```
| 服务器 | 角色 | Bot Name | Bot Key | Agent 名称 | Telegram User ID |
| ------- | --- | ----------------------------- | ------- | -------- | ---------------- |
| ubuntu1 | 风衡 | @shenwei_ubuntu1_fengheng_bot | | fengheng | 5038825565 |
| ubuntu1 | 风驰 | @shenwei_ubuntu1_fengchi_bot | | fengchi | 5038825565 |
| ubuntu1 | 风纪 | @shenwei_ubuntu1_fengji_bot | | fengji | 5038825565 |