系统系统服务器
野菜云服务器操作手册
目录
- 系统初始化配置
- 用户和权限管理
- 网络和防火墙配置
- 服务部署和管理
- 安全配置
- 监控和维护
- 备份和恢复
- 常用命令速查
系统初始化配置
1. 系统更新
1 2 3 4 5 6
| yum update -y yum install -y epel-release
apt update && apt upgrade -y
|
2. 安装常用工具
1 2 3 4 5
| yum install -y vim wget curl git net-tools htop iftop iotop lsof telnet nc
apt install -y vim wget curl git net-tools htop iftop iotop lsof telnet netcat
|
3. 时区配置
1 2 3 4 5 6 7 8 9 10
| timedatectl set-timezone Asia/Shanghai
timedatectl status
yum install -y ntp || apt install -y ntpdate systemctl enable ntpd systemctl start ntpd
|
用户和权限管理
1. 创建新用户
1 2 3 4 5 6 7
| useradd -m -s /bin/bash username passwd username
usermod -aG wheel username usermod -aG sudo username
|
2. SSH安全配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| vim /etc/ssh/sshd_config
Port 2222 PermitRootLogin no PasswordAuthentication no PubkeyAuthentication yes AllowUsers username MaxAuthTries 3 ClientAliveInterval 300
systemctl restart sshd
|
3. 密钥对配置
1 2 3 4 5
| ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-copy-id -i ~/.ssh/id_rsa.pub username@server_ip -p 2222
|
网络和防火墙配置
1. 防火墙管理 (firewalld)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| systemctl status firewalld firewall-cmd --state
systemctl start firewalld systemctl enable firewalld systemctl stop firewalld
firewall-cmd --list-all firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --remove-port=80/tcp --permanent firewall-cmd --reload
firewall-cmd --zone=public --add-service=http --permanent firewall-cmd --zone=public --add-service=https --permanent firewall-cmd --reload
|
2. 防火墙管理 (iptables)
1 2 3 4 5 6 7 8 9 10 11 12
| iptables -L -n
service iptables save
iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp --dport 443 -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -P INPUT DROP
|
3. 网络诊断
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| netstat -tunlp ss -tunlp
telnet host port nc -zv host port
traceroute domain.com tracepath domain.com
speedtest-cli
|
服务部署和管理
1. Web服务环境
Nginx安装配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| yum install -y nginx systemctl enable nginx systemctl start nginx
apt install -y nginx systemctl enable nginx systemctl start nginx
/etc/nginx/nginx.conf /etc/nginx/conf.d/ /var/www/html/
|
虚拟主机配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| server { listen 80; server_name example.com; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /static/ { alias /var/www/static/; expires 30d; } }
|
2. 数据库服务
MySQL安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm yum localinstall mysql80-community-release-el7-3.noarch.rpm yum install -y mysql-community-server
apt install -y mysql-server
mysql_secure_installation
systemctl enable mysqld systemctl start mysqld
|
Redis安装
1 2 3 4 5 6 7 8 9
| yum install -y redis systemctl enable redis systemctl start redis
apt install -y redis-server systemctl enable redis-server systemctl start redis-server
|
3. 应用部署
Node.js应用
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| curl -fsSL https://rpm.nodesource.com/setup_18.x | bash - yum install -y nodejs
cd /var/www/app npm install npm start
npm install -g pm2 pm2 start app.js pm2 startup pm2 save
|
Docker环境
1 2 3 4 5 6 7 8 9 10 11 12 13
| curl -fsSL https://get.docker.com | bash systemctl enable docker systemctl start docker
curl -L "https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
docker ps docker images docker logs container_name
|
安全配置
1. 系统安全加固
1 2 3 4 5 6 7 8 9 10 11
| systemctl disable bluetooth systemctl disable cups
vim /etc/ssh/sshd_config
yum install -y fail2ban || apt install -y fail2ban systemctl enable fail2ban systemctl start fail2ban
|
2. 安全扫描
1 2 3 4 5 6 7 8
| yum install -y lynis || apt install -y lynis
lynis audit system
nmap localhost
|
3. 日志监控
1 2 3 4 5 6 7 8 9
| /var/log/secure /var/log/messages /var/log/nginx/ /var/log/mysql/
tail -f /var/log/secure journalctl -f
|
监控和维护
1. 系统监控
1 2 3 4 5 6 7 8 9 10 11 12 13
| yum install -y htop || apt install -y htop
df -h du -sh /path/to/directory
free -h
uptime cat /proc/loadavg
|
2. 性能分析
1 2 3 4 5 6 7 8 9 10
| top
iostat -x 1 iotop
iftop nethogs
|
3. 定时任务
1 2 3 4 5 6 7 8 9 10 11
| crontab -e
0 2 * * * /root/scripts/backup.sh
0 3 * * 0 /root/scripts/clean_logs.sh
tail -f /var/log/cron
|
备份和恢复
1. 文件备份脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #!/bin/bash
BACKUP_DIR="/backup" DATE=$(date +%Y%m%d_%H%M%S) TAR_FILE="backup_$DATE.tar.gz"
tar -czf $BACKUP_DIR/$TAR_FILE \ /etc/ \ /var/www/ \ /home/ \ /root/scripts/
find $BACKUP_DIR -name "backup_*.tar.gz" -mtime +7 -delete
echo "Backup completed: $TAR_FILE"
|
2. 数据库备份
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #!/bin/bash
BACKUP_DIR="/backup/mysql" DATE=$(date +%Y%m%d_%H%M%S) USER="root" PASSWORD="your_password"
mysqldump -u$USER -p$PASSWORD --all-databases > $BACKUP_DIR/full_backup_$DATE.sql
gzip $BACKUP_DIR/full_backup_$DATE.sql
find $BACKUP_DIR -name "full_backup_*.sql.gz" -mtime +7 -delete
|
3. 自动化备份配置
1 2 3 4 5 6 7 8
| crontab -e
0 2 * * * /root/scripts/backup.sh
0 3 * * * /root/scripts/mysql_backup.sh
|
常用命令速查
系统信息
1 2 3 4 5
| uname -a cat /etc/redhat-release hostname whoami uptime
|
进程管理
1 2 3 4
| ps aux | grep nginx kill -9 PID pkill process_name nice -n 10 command
|
文件操作
1 2 3 4 5
| find / -name "filename" grep "pattern" /path/file tar -czf archive.tar.gz /dir tar -xzf archive.tar.gz rsync -av source/ dest/
|
网络工具
1 2 3 4
| ping host curl -I URL wget URL scp file user@host:/path
|
权限管理
1 2 3 4
| chmod 755 file chown user:group file chmod +x script.sh umask 022
|
系统服务
1 2 3 4 5 6
| systemctl status service_name systemctl start service_name systemctl stop service_name systemctl restart service_name systemctl enable service_name systemctl disable service_name
|
紧急情况处理
1. 无法连接服务器
- 检查云服务商控制台
- 查看VNC控制台
- 检查安全组规则
- 验证网络连通性
2. 磁盘空间不足
1 2 3 4 5 6
| find / -type f -size +100M
find /var/log -name "*.log" -mtime +7 -delete
yum clean all || apt clean
|
3. 性能问题诊断
1 2
| wget -qO- https://raw.githubusercontent.com/soyking/linux-check/master/linux-check.sh | bash
|
这份手册涵盖了云服务器管理的各个方面,建议根据实际需求选择相应的章节进行参考。记得定期更新和维护服务器,确保系统安全稳定运行。