From 03f2b710b04f8b5b8ddeec587380faccaa69e8ed Mon Sep 17 00:00:00 2001 From: hsc Date: Sun, 30 Mar 2025 14:27:57 +0800 Subject: [PATCH] =?UTF-8?q?chore:=E7=A7=BB=E5=8A=A8=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=88=B0=E5=AF=B9=E5=BA=94=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 17 +++++ sh/db/init_postgresql.sh | 103 +++++++++++++++++++++++++++++ sh/db/init_postgresql_bug.sh | 26 ++++++++ sh/git/init_gitea.sh | 117 +++++++++++++++++++++++++++++++++ sh/linux/init_linux.sh | 121 +++++++++++++++++++++++++++++++++++ sh/redis/fix_redis.sh | 84 ++++++++++++++++++++++++ sh/redis/init_redis.sh | 80 +++++++++++++++++++++++ sh/vpn/init_vpn.sh | 14 ++++ 8 files changed, 562 insertions(+) create mode 100644 readme.md create mode 100644 sh/db/init_postgresql.sh create mode 100644 sh/db/init_postgresql_bug.sh create mode 100644 sh/git/init_gitea.sh create mode 100644 sh/linux/init_linux.sh create mode 100644 sh/redis/fix_redis.sh create mode 100644 sh/redis/init_redis.sh create mode 100644 sh/vpn/init_vpn.sh diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a2b3a77 --- /dev/null +++ b/readme.md @@ -0,0 +1,17 @@ +# 🔧 工具箱 📂 代码片段集合 + +本仓库整理了日常开发中常用的代码片段,包含 **Shell 💻、Node.js 🚀、SQL 🛠️** 等语言,助力快速复用与效率提升! + +--- + +## 📋 目录 +1. **工具集合** 📦 → [跳转](#工具集合) +2. **使用指南** 📖 → [跳转](#使用指南) +3. **贡献说明** 👥 → [跳转](#贡献说明) +4. **联系作者** 📧 → [跳转](#联系作者) + +--- + + + + diff --git a/sh/db/init_postgresql.sh b/sh/db/init_postgresql.sh new file mode 100644 index 0000000..2e150e1 --- /dev/null +++ b/sh/db/init_postgresql.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +# PostgreSQL 14 安装配置脚本 (Rocky Linux 8.0) +# 数据库将安装在 /data/postgresql +# 账号: 1825713423 密码: hsc1825713423 + +# 检查是否为root用户 +if [ "$(id -u)" -ne 0 ]; then + echo "请使用root用户运行此脚本!" + exit 1 +fi + +# 1. 添加PostgreSQL官方仓库 +echo "添加PostgreSQL官方YUM仓库..." +dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm +dnf -qy module disable postgresql + +# 2. 安装PostgreSQL 14 +echo "安装PostgreSQL 14..." +dnf install -y postgresql14-server postgresql14-contrib + +# 3. 创建数据目录并初始化 +echo "创建数据目录并初始化数据库..." +mkdir -p /data/postgresql +chown postgres:postgres /data/postgresql + +sudo -u postgres /usr/pgsql-14/bin/initdb -D /data/postgresql + +# 4. 修改配置文件 +echo "配置PostgreSQL..." +cat > /data/postgresql/postgresql.conf < /data/postgresql/pg_hba.conf < /etc/systemd/system/postgresql-14.service < /data/postgresql/pg_hba.conf < $GITEA_CONFIG < /etc/systemd/system/gitea.service < /etc/chrony.conf < /etc/yum.repos.d/CentOS-Base.repo <> /etc/security/limits.conf +echo "* hard nofile 65535" >> /etc/security/limits.conf + +# 优化内核参数 +cat >> /etc/sysctl.conf <> "$REDIS_CONFIG" + echo "appendfsync everysec" >> "$REDIS_CONFIG" + + # 限制配置 + echo "配置连接限制..." + echo "maxclients 10000" >> "$REDIS_CONFIG" + echo "tcp-backlog 511" >> "$REDIS_CONFIG" + + # 防火墙配置 + echo "配置防火墙允许Redis端口 $REDIS_PORT..." + if command -v firewall-cmd &> /dev/null; then + firewall-cmd --permanent --add-port=$REDIS_PORT/tcp + firewall-cmd --reload + else + echo "未找到firewalld,请确保端口 $REDIS_PORT 已开放" + fi + + # 重启Redis服务 + echo "重启Redis服务应用配置..." + systemctl restart redis + + # 验证配置 + echo "验证Redis配置..." + echo "当前绑定IP:" + grep "^bind" "$REDIS_CONFIG" + echo "保护模式状态:" + grep "^protected-mode" "$REDIS_CONFIG" + echo "密码设置:" + grep "^requirepass" "$REDIS_CONFIG" + + # 测试远程连接 + echo "测试Redis连接..." + echo "本地连接测试:" + redis-cli -a "$REDIS_PASSWORD" ping + echo "如需远程测试,请在其他服务器执行:" + echo "redis-cli -h <你的服务器IP> -p $REDIS_PORT -a $REDIS_PASSWORD ping" + + # 完成信息 + echo "Redis基础配置完成!" + echo "重要信息:" + echo "- Redis密码: $REDIS_PASSWORD" + echo "- 监听端口: $REDIS_PORT" + echo "- 绑定IP: $REDIS_BIND_IP (允许所有IP访问)" + echo "- 配置文件: $REDIS_CONFIG" + echo "- 管理命令: systemctl [start|stop|restart|status] redis" + echo "注意: 请确保服务器安全组/防火墙已开放 $REDIS_PORT 端口" diff --git a/sh/redis/init_redis.sh b/sh/redis/init_redis.sh new file mode 100644 index 0000000..6b91dde --- /dev/null +++ b/sh/redis/init_redis.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# Rocky Linux 8 Redis 5.x 安装脚本修复版 +# 密码设置为: hsc1825713423 + +# 检查是否为root用户 +if [ "$(id -u)" -ne 0 ]; then + echo "请使用root用户运行此脚本!" + exit 1 +fi + +# 安装EPEL仓库 +echo "正在安装EPEL仓库..." +dnf install -y epel-release + +# 安装Redis 5.x +echo "正在安装Redis 5.x..." +dnf install -y redis + +# 查找Redis实际安装路径 +REDIS_SERVER_PATH=$(which redis-server) +echo "检测到Redis安装路径: $REDIS_SERVER_PATH" + +# 创建正确的systemd服务文件 +echo "正在修复systemd服务配置..." +cat > /etc/systemd/system/redis.service <