Skip to content

Commit

Permalink
update Linux book
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy committed Jan 2, 2025
1 parent eb9f7c8 commit 3481675
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Docs/Linux/NewNginx.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ tar -xf nginx-1.26.2.tar.gz
```bash
sudo apt install gcc make libpcre3 libpcre3-dev libssl-dev

```
### 当需要编译ngx_postgres模块时需手动配置config

```ini
ngx_addon_name=ngx_postgres

HTTP_MODULES="$HTTP_MODULES ngx_postgres_module"
# 添加include lib
CORE_INCS="$CORE_INCS /usr/local/pgsql/include"
CORE_LIBS="$CORE_LIBS /usr/local/pgsql/lib/libpq.so"

NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_postgres_escape.c $ngx_addon_dir/src/ngx_postgres_handler.c $ngx_addon_dir/src/ngx_postgres_keepalive.c $ngx_addon_dir/src/ngx_postgres_module.c $ngx_addon_dir/src/ngx_postgres_output.c $ngx_addon_dir/src/ngx_postgres_processor.c $ngx_addon_dir/src/ngx_postgres_rewrite.c $ngx_addon_dir/src/ngx_postgres_upstream.c $ngx_addon_dir/src/ngx_postgres_util.c $ngx_addon_dir/src/ngx_postgres_variable.c"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_postgres_escape.h $ngx_addon_dir/src/ngx_postgres_handler.h $ngx_addon_dir/src/ngx_postgres_keepalive.h $ngx_addon_dir/src/ngx_postgres_module.h $ngx_addon_dir/src/ngx_postgres_output.h $ngx_addon_dir/src/ngx_postgres_processor.h $ngx_addon_dir/src/ngx_postgres_rewrite.h $ngx_addon_dir/src/ngx_postgres_upstream.h $ngx_addon_dir/src/ngx_postgres_util.h $ngx_addon_dir/src/ngx_postgres_variable.h $ngx_addon_dir/src/ngx_postgres_ddebug.h $ngx_addon_dir/src/resty_dbd_stream.h"

have=NGX_POSTGRES_MODULE . auto/have
```

### 编译前配置
Expand Down
16 changes: 16 additions & 0 deletions Docs/Linux/NewPosgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ cd /usr/loacl/pgsql/bin
./initdb -D /home/pgadmin/data -U pgadmin
```

### 配置环境变量

#### 将配置写入rc
```bash
.zshrc
# postgresql
export PGHOME=/usr/local/pgsql
export PGDATA=/home/pgadmin/data
export PATH=$PATH:$PGHOME/bin
# 设置动态库收索目录
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib/
```

重启wsl


### 远程访问
```bash
# 进入数据库目录
Expand Down
66 changes: 66 additions & 0 deletions Docs/Linux/NewWsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,70 @@ wsl --install -d Debian
sudo apt install netselect-apt
sudo netselect-apt -c CN bookworm && sudo mv sources.list /etc/apt/sources.list
```
## 系统备份和还原

### 安装btrfs

```bash
sudo apt-get update
sudo apt-get install btrfs-progs
```

### 备份和还原脚本

```bash
#!/bin/bash
# 默认不还原
RESTORE=false
# 检查是否提供了时间参数
if [ "$1" ]; then
RESTORE=true
RESTORE_TIME="$1"
fi
# 备份源目录
SOURCE_DIR="/"
# VHDX 文件路径
VHDX_FILE="/mnt/x/WSL/backup/backup.vhdx"
# 挂载点
MOUNT_POINT="/mnt/backup"
# 检查 VHDX 文件是否存在
if [ ! -f "$VHDX_FILE" ]; then
echo "VHDX 文件不存在: $VHDX_FILE"
echo "创建新的 VHDX 文件..."
dd if=/dev/zero of=$VHDX_FILE bs=1M count=10240
mkfs.btrfs $VHDX_FILE
fi
# 挂载 VHDX 文件
mkdir -p $MOUNT_POINT
mount -o loop $VHDX_FILE $MOUNT_POINT
if [ "$RESTORE" = true ]; then
# 还原系统到指定时间
RESTORE_DIR="$MOUNT_POINT/$RESTORE_TIME"
if [ ! -d "$RESTORE_DIR" ]; then
echo "指定的还原时间目录不存在: $RESTORE_DIR"
umount $MOUNT_POINT
exit 1
fi
btrfs subvolume snapshot $RESTORE_DIR $SOURCE_DIR
echo "系统已还原到: $RESTORE_TIME"
else
# 备份目标目录
DEST_DIR="$MOUNT_POINT/$(date +\%Y-\%m-\%d)"
# 创建快照
btrfs subvolume snapshot $SOURCE_DIR $DEST_DIR
echo "系统已备份到: $DEST_DIR"
fi
# 卸载 VHDX 文件
umount $MOUNT_POINT
```

0 comments on commit 3481675

Please sign in to comment.