一、资源管理
cat /etc/os-release
lscpu
lsusb
lspci
free -h
top
ps -ef
kill -9 PID
二、基础
systemctl poweroff
init 0
systemctl reboot
init 6
source /etc/profile
which shutdown
whereis shutdown
chmod +x /etc/rc.local
vi /etc/rc.local
vi /etc/crontab
alias 'node-2' 'ssh root@192.168.1.1'
alias -p
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.25.53.123
三、网络相关
ip addr
ifconfig
nmcli
lsof -i
netstat -nlp
nmcli con show
nmcli con mod eth0 ip4 192.168.0.100/24 gw4 192.168.0.254
nmcli con mod eth0 ipv4.dns "223.5.5.5 223.6.6.6"
nmcli con mod eth0 ipv4.method manual
nmcli con mod eth0 connection.autoconnect yes
nmcli con mod eth0 ip4 192.168.1.200/24 gw4 192.168.1.253 ipv4.dns "223.5.5.5 223.6.6.6" ipv4.method manual connection.autoconnect yes
curl https://mirrors.aliyun.com/repo/Centos-8.repo
curl -O https://mirrors.aliyun.com/repo/Centos-8.repo
wget https://mirrors.aliyun.com/repo/Centos-8.repo
curl https://mirrors.aliyun.com/repo/Centos-8.repo -o /tmp/CentOS-Base.repo
wget https://mirrors.aliyun.com/repo/Centos-8.repo -O /etc/yum.repos.d/CentOS-Base.repo
smbclient -L 192.168.2.231 -U 用户名
smbclient //192.168.2.231/临时 -U 用户名
sestatus
semanage port -l | grep ssh
semanage port -a -t ssh_port_t -p tcp 10022
四、主机名、语言、时间日期
hostnamectl
hostnamectl set-hostname NAME
hostnamectl --transient set-hostname NAME
localectl status
localectl list-locales
localectl set-locale LANG=zh_CN.UTF-8
timedatectl
timedatectl set-time '2021-12-05 10:25:00'
timedatectl list-timezones
timedatectl set-timezone Asia/Shanghai
vi /etc/systemd/timesyncd.conf
timedatectl set-ntp yes
timedatectl show-timesync
timedatectl timesync-status
五、用户和组
cat /etc/group
groupadd hausers
cat /etc/passwd
useradd hauser -m -g hausers -s /bin/bash -d /home/hauser
passwd hauser
cat /etc/group | grep sudo
usermod -aG sudo hauser
visudo
su -l hauser
六、软件包
6.1 dnf(yum)、rpm包管理器
dnf install net-tools
dnf repolist
dnf search postgresql
dnf download postgresql
dnf download --resolve postgresql
dnf download --resolve --alldeps postgresql
dnf list installed
dnf remove postgresql
dnf clean all
dnf makecache
dnf provides ifconfig
dnf group list hidden
dnf group info 'Development Tools'
dnf group install 'Development Tools'
dnf group remove 'Development Tools'
dnf config-manager --add-repo file:///mnt/iso
rpm -qa
rpm -ivh net-tools-2.0-0.54.oe1.x86_64.rpm
rpm -e net-tools
rpm -ql net-tools
6.2 apt、deb包管理器
apt install net-tools
apt-cache stats
apt policy
apt search postgresql-server
apt download mariadb-server
apt install mariadb-server -d
apt list --installed
apt remove net-tools
apt clean
apt update
apt update --allow-unauthenticated
apt-file search ifconfig
apt-cdrom -d=/media/cdrom add
dpkg -l
dpkg -i mariadb-server_10.3.31-0+deb10u1_all.deb
dpkg -r mariadb-server
dpkg -L mariadb-server
七、服务管理
systemctl list-units --type service
systemctl list-units --type service --all
systemctl status rsyslog
systemctl start rsyslog
systemctl stop rsyslog
systemctl restart rsyslog
systemctl enable rsyslog
systemctl enable --now docker
systemctl disable rsyslog
systemctl daemon-reload
八、文件和目录
touch xxxx.xx
mkdir -p /xxxxx
mv 源 目标
cp -r 源 目标
rm -rf 目标
ln -s 源 目标
cat xxxx
vi xxxx
nano xxxx
find 目录 -name "文件名"
tail -f /var/log/messages
sed -i 's/目标/被替换/g' 文件名
grep -v '正则'
grep -v '#'
grep -v '^$'
chmod 775 xxxx
chown -R 用户.用户组 xxxx
du -sh
du -hd1
ls -hla
tar -zxvf xxx.tar.gz -C /usr/local/
tar -zcvf xxx.tar.gz /user/local
scp 本地文件 用户名@主机:远程文件
scp -r 本地目录 用户名@主机:远程目录
sync
locate xxxx
九、磁盘管理
ls /sys/class/scsi_host
echo '- - -' > /sys/class/scsi_host/host0/scan
fdisk --list
fdisk /dev/sdb
cfdisk /dev/sdb
mkfs.ext4 /dev/sdb1
e2fsck -f /dev/sdb1
mount 分区 目标
blkid
nano /etc/fstab
umount 目标
dd if=/dev/zero of=/dev/sdb bs=8192K count=1
df -h
growpart /dev/sda 2
十、防火墙
10.1 firewalld防火墙
firewall-cmd --list-all
firewall-cmd --get-services
firewall-cmd --zone=public --add-service=postgresql --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --remove-port=80/tcp --permanent
firewall-cmd --permanent --new-service=myssh
firewall-cmd --permanent --service=myssh --add-port=10022/tcp
firewall-cmd --permanent --service=myssh --get-ports
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.1" service name="myssh" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="3306" accept"
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="3306" accept"
firewall-cmd --reload
10.2 ufw防火墙
apt install ufw
ufw allow ssh
ufw allow 80/tcp
ufw allow 8000:8006/tcp
ufw allow from 8.8.8.8
ufw allow from 192.168.1.0/24
ufw enable
ufw status numbered
ufw delete allow 80/tcp
ufw reload
ufw status verbose
10.3 iptable防火墙
iptables -L
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
service iptables save
十一、grub引导
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-set-default 0
grub2-editenv list
grep 'menuentry ' /boot/grub2/grub.cfg