Skip to content

Trojan 服务端操作

bash
# 查看状态(显示绿色 active(running) 表示正常运行中)
systemctl status trojan.service
systemctl status trojan

# 启动
systemctl start trojan

# 重启
systemctl restart trojan

# 关闭
systemctl stop trojan

# 开机自动启动
systemctl enable trojan

# 禁止开机自动启动
systemctl disable trojan

# 错误查询(日志查看工具)
journalctl -e -u trojan.service

# 快速查看监听端口
sudo ss -tulnp

# 编辑密码
vim /etc/trojan/config.json

一键搭建脚本

bash
wget -N --no-check-certificate -q -O trojan_install.sh "https://raw.githubusercontent.com/xyz690/Trojan/master/trojan_install.sh" && chmod +x trojan_install.sh && bash trojan_install.sh

Nginx 基本操作

  • web 服务器默认目录:/var/www/html
  • nginx html 目录:/usr/share/nginx/html
  • nginx 配置目录:/etc/nginx/nginx.conf
bash
# 测试配置文件
nginx -t

# 重载
nginx -s reload
# 或
sudo systemctl reload nginx

Docker 操作

1. 更新系统包

bash
# Ubuntu/Debian
sudo apt update

# CentOS/RHEL
sudo yum update

2. 安装依赖

bash
# Ubuntu/Debian
sudo apt install -y ca-certificates curl gnupg lsb-release

# CentOS/RHEL
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

3. 添加 Docker 官方仓库

bash
# Ubuntu/Debian
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# CentOS/RHEL
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

4. 安装 Docker

bash
# Ubuntu/Debian
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io

# CentOS/RHEL
sudo yum install -y docker-ce docker-ce-cli containerd.io

5. 管理 Docker 服务

bash
# 启动并设置开机自启
sudo systemctl start docker
sudo systemctl enable docker

# 查看状态
sudo systemctl status docker

# 重启
sudo systemctl restart docker

# 停止
sudo systemctl stop docker

# 禁用(防重启)
sudo systemctl disable docker.socket

6. 配置与权限

bash
# 添加用户到 docker 组(避免每次使用 sudo)
sudo usermod -aG docker $USER
sudo usermod -aG docker jenkins

# 配置国内镜像加速
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://docker.nju.edu.cn",
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com",
    "https://docker.nastool.de",
    "https://docker.1ms.run",
    "https://docker.1panel.live",
    "https://hub1.nat.tf",
    "https://docker.1panel.top",
    "https://dockerpull.org",
    "https://docker.13140521.xyz"
  ]
}
EOF
sudo systemctl restart docker

修改 docker 配置文件:/usr/lib/systemd/system/docker.service,修改后执行:

bash
systemctl daemon-reload

镜像监控:https://status.anye.xyz/

7. 常用操作

bash
# 容器管理
docker ps                          # 查看运行中的容器
docker ps -a                       # 查看所有容器
docker exec -it <容器> bash       # 进入容器

# 运行临时容器(退出后自动删除)
docker run --rm -p 8080:80 my-web-server

# 查看系统信息
echo "IP: $(hostname -I | awk '{print $1}')"
echo "用户: $(whoami)"
which docker

Docker Compose 操作

bash
docker-compose ps
docker-compose logs <服务>
docker-compose down
docker-compose build
docker-compose up -d

# 查看容器日志
docker logs <容器> -f

# 重建单个服务
sudo docker-compose down <服务>
sudo docker-compose build --no-cache <服务>
sudo docker-compose up -d <服务>