初始化配置
# 配置时区
timedatectl set-timezone Asia/Shanghai
# 关闭邮件服务
systemctl stop [email protected] \
; systemctl disable [email protected]
# 配置Shell提示符
echo "PS1='\[\e[36;40m\][\D{%Y-%m-%d} \A] \[\e[0m\] \[\e[35;40m\]\w\[\e[0m\]\n\[\e[33;40m\][\u@\H]\[\e[0m\] \\$ '" >> ~/.bashrc
# 打开自定义命令
sed -E -i.bak \
-e '/(export|eval|alias (ls|ll|l|rm|cp|mv))/s/^# //' ~/.bashrc \
&& . ~/.bashrc
# 配置 sshd
# 允许root密码登录
# 允许密码登录
# 解决SSH自动断开问题
sed -E -i.bak \
-e 's/#(Port 22)/\1/' \
-e 's/#(PermitRootLogin) prohibit-password/\1 yes/' \
-e 's/#(PubkeyAuthentication yes)/\1/' \
-e 's/#(PasswordAuthentication yes)/\1/' \
-e 's/#(AllowTcpForwarding yes)/\1/' \
-e 's/(X11Forwarding yes)/#\1/' \
-e 's/#(Compression delayed)/\1/' \
-e 's/#(ClientAliveInterval) 0/\1 60/' \
-e 's/#(ClientAliveCountMax) 3/\1 3/' \
/etc/ssh/sshd_config \
&& systemctl restart sshd.service
软件更新
软件库管理
配置防火墙
iptables 配置
关闭IPv6
# /etc/sysctl.conf
# 禁用所有接口的IPv6
net.ipv6.conf.all.disable_ipv6 = 1
# 禁用默认接口的IPv6
net.ipv6.conf.default.disable_ipv6 = 1
# 禁用特定接口(如eth0)的IPv6,将eth0替换为你的实际接口名
net.ipv6.conf.eth0.disable_ipv6 = 1
# /etc/hosts
# ::1 ......
远程公私钥登录
# 生成公钥、私钥
ssh-keygen -t rsa -b 4096 -C "[email protected]"
...
Enter a file in which to save the key (/home/you/.ssh/algorithm): <key_name>
Enter passphrase (empty for no passphrase): [输入密码]
Enter same passphrase again: [再次输入密码]
# 设置访问权限
cd ~/.ssh
chmod 600 <key_name>
# 将公钥追加到 authorized_keys 文件,可追加多个公钥
cat <key.pub> >> authorized_keys
# 私钥在 SSH 登录时使用
网络端口操作
# 查看端口占用
# 查看所有端口占用情况
netstat -tlunp
# 查看指定端口占用情况
netstat -tlunp | grep <port>
查看系统版本
lsb_release -a
cat /etc/redhat-release
cat /etc/issue
系统进程操作
# 定位高CPU占用
ps H -eo user,pid,ppid,tid,time,%cpu,cmd --sort=%cpu
# 可视化显示CPU的使用状况的工具
yum install -y htop
htop
# 查看进程的启动目录
ls -l /proc/<PID>/cwd
硬件
# 查看硬件信息
hwinfo --short
# 查看内核提示的缺失驱动
dmesg | grep -i "firmware\|error"
磁盘操作
# 修改硬盘挂载目录
# 卸载硬盘
umount -v /mnt/raid1-2disk-500G
# 修改挂载目录
mv /mnt/raid1-2disk-500G /mnt/raid1-250G-2disk
# 修改/etc/fstab文件里的挂载目录
nano /etc/fstab
# 重装挂载
mount -av /dev/md127 /mnt/raid1-250G-2disk
修改密码
查看文件夹大小
du -h --max-depth=1 <path>
实时查看文件变化
apt install inotify-tools
inotifywait -m -r -e modify,create,delete <path>
使用ssh跳转
ssh -p 2222 \
-i ~/.ssh/cuile.key \
-L localhost:5432:169.254.0.4:8888 \
-o StrictHostKeyChecking=accept-new \
-o SessionType=none \
-o Compression=yes \
-o BatchMode=yes \
-o AddressFamily=inet \
[email protected]
# 测试代码网络
curl -x http://localhost:5432 ifconfig.me
# 返回代理服务器的IP,即为成功。
传输文件
# 拉取文件
scp -i ~/.ssh/cuile.key \
-P 28883 \
[email protected]:~/Container-SmartDNS/smartdns.tar /root/Container-SmartDNS/
# 推送文件
scp -i ~/.ssh/cuile.key \
-P 28883 \
/root/Container-SmartDNS/ [email protected]:~/Container-SmartDNS/smartdns.tar