commit c4f19befa7321c0137c711e760ff48ed10eeec78 Author: mini2024 Date: Sun Mar 9 23:14:21 2025 +0800 Update diff --git a/1.sh b/1.sh new file mode 100644 index 0000000..48a26ce --- /dev/null +++ b/1.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# curl -fsSL scripts.oo1.dev/1.sh | env NZ_client_secret=x bash + +set -e # 遇到错误即退出 +trap 'echo "Error on line $LINENO"' ERR + +print_red() { echo -e "\033[31m\033[01m$1$2\033[0m"; } +print_green() { echo -e "\033[32m\033[01m$1$2\033[0m"; } +print_yellow() { echo -e "\033[33m\033[01m$1$2\033[0m"; } + +install_docker() { + print_green "###################" + print_green "##### docker ######" + print_green "###################" + if [ -x "$(command -v docker)" ]; then + echo "Docker 已安装" + else + echo "Docker 未安装,正在安装中..." + curl -fsSL https://get.docker.com/ | sh + fi +} + +sysctl_config() { + print_green "###################" + print_green "##### sysctl ######" + print_green "###################" + SYSCTL_SETTINGS=( + "net.core.rmem_max=16777216" + "net.core.wmem_max=16777216" + "net.core.default_qdisc=fq" + "net.ipv4.tcp_congestion_control=bbr" + "net.ipv4.tcp_slow_start_after_idle=0" + "net.ipv4.tcp_notsent_lowat=16384" + # "net.ipv4.tcp_notsent_lowat=131072" + ) + for SETTING in "${SYSCTL_SETTINGS[@]}"; do # 遍历数组 + KEY=$(echo "$SETTING" | cut -d '=' -f 1) # 截取=左边的字符串 + sed -i "/^$KEY *= *[0-9]*/d" /etc/sysctl.conf # 删除已有的配置 + echo "$SETTING" >>/etc/sysctl.conf # 追加新的配置 + # echo "已添加系统配置: $SETTING" # 输出提示信息 + done # 循环结束 + sysctl -p +} + +modify_authorized_keys() { + print_green "###################" + print_green "# authorized_keys #" + print_green "###################" + echo "正在修改 authorized_keys" + mkdir -p /root/.ssh/ + AUTHORIZED_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDi6fLhEYp2mmUUBOB/6CA0iQYcwhAUVBwpbJJhK0fZmvmtrCrfkDvFtqw4WH0D/DgRtJNyoDfrQ2gm67FtFzu2ZfH0PtIEI6JWrh432qjQnAT5cuKbN3ghrjTHf08vjh0axxilSFtCXf5Gyv+ZnABil7GZAhJB5K/yBUMr6OD5fp4tvjAYe0t6ZIQb8vgd0dCXDGA3Rak1B7W24vDA1Col+Qvx5I7pfqiebkof7BbkfBYX5KZ/ArK0n1RV7wBjf6g/XkwRPvpCR5rz7s+UnMr2FFYqfQ1wkpKjo74KzAahFyy7UicM3e7OKfZvd8EmWBysIdKCcl9s/H9Z4Q/TDZsmnr68KweCvpqFVHfKS9CZ/7w/7zQhrXDhnysqt6nmp/moQLMax6b62++4X6E0gyopc2nlMT+QjIwRPl+DPC2UicWniOSAuSvpPxt8YXF4Zbpsg0efMQvHDrjQF6Ws9UIKVQeTBqij+TJ3w5aUbLEjPhrP5ia7Dtn7u/3IsosxW00= yanhao@yanhaodeMacBook-Pro.local" + echo $AUTHORIZED_KEY >/root/.ssh/authorized_keys + chmod 600 /root/.ssh/authorized_keys + # wget -q -O /tmp/sshd_config https://script.yanhao.ren/downloads/sshd_config + # mv /tmp/sshd_config /etc/ssh/sshd_config + # service sshd restart +} + +bash_aliases() { + print_green "###################" + print_green "## bash_aliases ###" + print_green "###################" + rm -f /root/.bash_aliases + # 确保 .bashrc 包含别名加载代码 + touch /root/.bash_aliases + grep -q "/root/.bash_aliases" /root/.bashrc || echo ' +if [ -f /root/.bash_aliases ]; then + . ~/.bash_aliases +fi' >>/root/.bashrc + + cat <<'EOF' >/root/.bash_aliases +alias maddy='docker exec -it maddy maddy' +alias l='ls -l' +alias ll='ls -alF' +alias telnet='docker run --quiet --rm --network host --entrypoint telnet busybox:latest' +alias dstats='docker stats --no-stream' +alias dup='docker compose up --remove-orphans' +alias dps='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Size}}"' +EOF + + print_yellow "别名配置已完成,请执行 source /root/.bashrc 使配置生效" +} + + +modify_authorized_keys +bash_aliases +install_docker +sysctl_config +source <(curl -fsSL scripts.oo1.dev/nezha-v1.sh) diff --git a/alpine.sh b/alpine.sh new file mode 100644 index 0000000..fd92bbe --- /dev/null +++ b/alpine.sh @@ -0,0 +1,23 @@ +cat < /etc/apk/repositories +http://dl-cdn.alpinelinux.org/alpine/v3.21/main +http://dl-cdn.alpinelinux.org/alpine/v3.21/community +EOF + +# 更新软件包索引 +apk update +# 升级所有软件包 +apk upgrade --available + +# 清理缓存 +apk cache clean +# 更彻底地清理 +# rm -rf /var/cache/apk/* + +# 检查是否有失败的服务(OpenRC等效命令) +rc-status --crashed || echo "没有检测到失败的服务" + +# 重启系统 +# reboot + +# 判断是否需要重启 +# https://github.com/copilot/share/42124018-0980-80c5-8001-a60ae0644914 \ No newline at end of file diff --git a/nezha-v1.sh b/nezha-v1.sh new file mode 100644 index 0000000..2ac596a --- /dev/null +++ b/nezha-v1.sh @@ -0,0 +1,146 @@ +#!/bin/bash +print_green "###################" +print_green "### nezha_agent ###" +print_green "###################" + +declare -r service_file="/etc/systemd/system/nezha-agent.service" +NZ_uuid="" + +uninstall_nezha_agent() { + echo "卸载哪吒监控代理" + systemctl stop nezha-agent || true + systemctl disable nezha-agent || true + rm -rf /etc/systemd/system/nezha-agent.service + rm -rf /opt/nezha/agent/* +} + +set_uuid() { + # 首先尝试从 config.yml 获取 UUID + if [ -f "/opt/nezha/agent/config.yml" ]; then + config_uuid=$(grep "uuid:" "/opt/nezha/agent/config.yml" | awk '{print $2}') + if [ ! -z "$config_uuid" ]; then + NZ_uuid=$config_uuid + echo "从 config.yml 获取到 UUID: $NZ_uuid" + return + fi + fi + + # 尝试从服务文件获取 UUID + if [ -f "/etc/systemd/system/nezha-agent.service" ]; then + existing_uuid=$(grep "NZ_uuid=" "/etc/systemd/system/nezha-agent.service" | cut -d'=' -f2 | tr -d '"') + if [ ! -z "$existing_uuid" ]; then + NZ_uuid=$existing_uuid + echo "从服务文件获取到 UUID: $NZ_uuid" + return + fi + fi + + # 如果无法从服务文件获取,则生成新的 UUID + new_uuid=$(cat /proc/sys/kernel/random/uuid) + if [ ! -z "$new_uuid" ]; then + NZ_uuid=$new_uuid + echo "生成新的 UUID: $NZ_uuid" + else + echo "无法生成 UUID" + exit 1 + fi +} + +start_nezha_agent() { + echo "启动哪吒监控代理..." + if ! id "nezha" &>/dev/null; then + useradd -r -s /sbin/nologin nezha + fi + chown -R nezha:nezha /opt/nezha + chmod -R u+rx /opt/nezha/agent/nezha-agent + systemctl daemon-reload + systemctl enable nezha-agent + systemctl start nezha-agent + sleep 1 + systemctl status nezha-agent +} + +detect_arch() { + arch=$(uname -m) + case $arch in + amd64|x86_64) + os_arch="amd64" + ;; + aarch64|arm64) + os_arch="arm64" + ;; + *) + echo "不支持的系统架构: $arch" + exit 1 + ;; + esac + echo "检测到系统架构: $os_arch" +} + +down_nezha_agent() { + os="linux" + GITHUB_URL="gh-cf.oo1.dev/github.com" + NZ_AGENT_URL="https://${GITHUB_URL}/nezhahq/agent/releases/latest/download/nezha-agent_${os}_${os_arch}.zip" + echo "正在下载哪吒监控代理: $NZ_AGENT_URL" + curl -L -o /tmp/nezha-agent.zip $NZ_AGENT_URL + mkdir -p /opt/nezha/agent + unzip -o /tmp/nezha-agent.zip -d /opt/nezha/agent + rm -f /tmp/nezha-agent.zip +} + +write_service_file() { + echo "正在写入系统服务配置文件..." + cat >"${service_file}" <