rhel/centos/rocky/fedora/aliyun (dnf,yum,rpm,snap)
ubuntu/debian (apt,deb,snap)
系统
cat /etc/os-release查看系统信息hostnamectl查看版本信息df -h磁盘空间使用情况free -h查看内存使用状况lscpucpu相关reboot重启halt关机clear CTRL+L清屏nohup frpc -c frpc.toml &后台启动软件版本
ldd --version查看glibc版本git -v查看git版本ssh -V判断是否安装客户端目录文件操作
cd ~进入root目录whereis redis-cli查看路径pwd当前路径lsls -l查看目录和详情mkdir a a1创建两个目录mkdir -m 777 a带权限chmod 777 filename赋予权限chmod -R 777 api/全部赋予权限mv dir1 dir2以动或重命名可以是文件或文件夹rm -rf *清空当前目录rm -rf dir1强制删除目录和内容,f是不提示cp –r test/ newtest复制全部内容包括子目录,复制单文件不需要r,目录时候必须要find /root/ -iname redis查找文件-iname不区分大小写grep -r "关键词" /路径路径下查找文件名ln -s file1 lnk1创建一个指向文件或目录的软链接ln -s /root/gf /usr/bin软连接用户和组
sudo以root权限执行命令passwd root修改root密码passwd postgres修改密码- ubuntu默认密码账号ubuntu|rockylinux
su -切换到rootsu postgres切换用户postgresuseradd postgres添加用户userdel postgres删除用户usermod -a -G groupname username添加用户到组groupadd postgresgroupdel postgres添加删除组w查看登陆用户id当前用户lastlog查看所有用户cat /etc/passwd查看所有用户路径进程端口
ps aux查看全部进程ps -ef查看所有程序top动态进程ps -ef | grep weui查看某个应用进程lsof -i:4443查看某个端口进程kill 19999关闭pid端口进程pkill caddy关闭多个进程名称ss -tunlpa查看全部端口网络
ifconfig查看网络ip a查看iproute -n查看路由pingping网址curl http://localhostwget -O file url下载分区
dd if=/dev/zero of=/swap1 bs=1M count=2048创建交换分区mkswap /swap1创建swapon /swap1启用压缩解压
tar -xzvf 1.tar.gzgz解压tar -czvf 1.tar.gz 1.cgz压缩文件夹或文件zip -r 1.zip /homezip文件压缩备份 后面是压缩某个文件夹绝对路径unzip 1.zip解压zip7z a 1.7z ./html压缩支持多个文件夹 有些系统7za7z x 1.7z解压当前目录7z x 1.7z -o./qq到指定qq目录防火墙
ufw enable && ufw default deny启动防火墙ufw status列出所有ufw allow 9999ufw allow 22/tcp允许端口ufw delete allow 9999删除端口ufw versionvi或vim操作配置
- ESC :q 退出 | :wq! 退出并保存| 按I键 进入输入模式
echo $PATH类似win的pathexport CGO_ENABLED=1导入变量export CC=/usr/local/musl/bin/musl-gcc编译musl-gccvi /etc/profile末尾加入export PATH=$PATH:/root/bin多个用:分割source /etc/profile立即生效上面修改vi /etc/init.wsl自动启动文件vi /etc/ssh/sshd_config编辑此文件内容如下Port 22 PermitRootLogin yesnano
nano ./1.txt
ctrl +o 保存 ctrl + x退出 ctrl+k 剪切当前行 ctrl+u粘贴
systemd
systemctl list-unit-files --type=service --state=enabled查看开机启动项systemctl list-units --type=service --state=running显示当前活跃(运行中)的服务- 服务管理
systemctl start x 启动服务 systemctl stop x 停止 systemctl restart x 重启 systemctl reload x 重载 推荐 systemctl enable x 开机 systemctl disable x 取消开机 systemctl status x 状态 systemctl show x 查看 systemctl daemon-reload 重载sysyemd服务编译程序
./configuremake && make install
nginx
apt install nginxdnf install nginxcurl http://localhost 测试systemctl start nginx systemctl stop nginx systemctl reload nginx systemctl restart nginx systemctl enable nginx systemctl status nginxnginx -V查看模块nginx -t查看配置/etc/nginx/conf.d/配置文件 默认 root /usr/share/nginx/html 默认网站目录vi /etc/yum.repos.d/nginx.repo 添加官方源禁止缓存 location ~* \.(js|css|png|jpg|gif|webp)$ { add_header Cache-Control no-store; } 防盗链 location ~* \.(gif|jpg|png)$ { valid_referers none blocked 192.168.0.1; if ($invalid_referer) { rewrite ^/ http://$host/logo.png; } } 显示目录 autoindex on; autoindex_exact_size off; autoindex_localtime on;ubuntu添加源[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.keycurl -fSsL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginxmysql
apt install mysql-servermysql_secure_installation初始化
移除匿名用户 y 禁止root远程n 移除test数据库y 加载权限表y
首次输入mysql设置密码USE mysql; SELECT user, host FROM user WHERE user = 'root'; -- 必须看到 `root`@`%` 这条记录,否则重新创建: CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Mysql@1234'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Mysql@1234'; --添加密码 FLUSH PRIVILEGES; EXIT;mysql -u root -p登陆/etc/mysql/mysql.conf.d/mysqld.cnf127.0.0.1改成0.0.0.0systemctl restart mysql重启systemctl status mysql查看状态mysql -Vmysqldump -u root -p testdb > aa.sql备份数据库mysqldump -u root -p testdb | gzip > aaa.sql.gzpgsql
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.listapt-cache search postgresql | grep postgresql-[0-9]查看可选版本apt install -y postgresql-18 postgresql-client-18psql -Vsudo -u postgres psql修改密码 \q 退出ALTER USER postgres WITH PASSWORD 'pgsql';用户postgressystemctl restart postgresql重启/etc/postgresql/18/main/postgresql.conf修改listen_addresses = '*'/etc/postgresql/18/main/pg_hba.conf添加host all all 0.0.0.0/0 md5psql -h 121.41.165.27 -p 5432 -U postgres -d postgres登陆sudo -u postgres pg_dump testdb > ppp.sql备份php
apt install -y php8.3 php8.3-fpm php8.3-cli php8.3-commonapt install -y php8.3-mysql php8.3-pgsql php8.3-redis php8.3-mbstring php8.3-xml php8.3-curl php8.3-zip php8.3-gdapt install -y php7.2 php7.2-fpm php7.2-cli php7.2-commonapt install -y php7.2-mysql php7.2-pgsql php7.2-redis php7.2-mbstring php7.2-xml php7.2-curl php7.2-zip php7.2-gdphp -vphp -m查看版本和模块apt install -y software-properties-commonsudo add-apt-repository ppa:ondrej/php && apt updatesystemctl status php8.3-fpmsystemctl restart php8.3-fpmsystemctl start php8.3-fpm/etc/php/8.3/fpm/php.ini配置sudo update-alternatives --set php /usr/bin/php7.2指定版本/etc/nginx/nginx.conf配置user www-data;和php保持一致/etc/php/7.2/fpm/pool.d/www.conf配置一致apt purge -y php8.3*卸载apt autoremove -yapt autoclean -ysnap安装
dnf install snapd -ysystemctl enable --now snapd.socketln -s /var/lib/snapd/snap /snap经典模式systemctl start snapd启动systemctl enable snapd开机启动snap install snap-store-proxy加速,一般不需要snap find qq# 搜索snap list# 查看已安装列表snap refresh# 更新所有包snap remove msedit# 卸载软件snap services查看snap开机启动项/var/snap/安装程序配置文件apt/deb
- /etc/apt/sources.list.d 这是第三方软件列表
grep -i "install" /var/log/apt/history.log查看安装列表apt install ./package_name.debapt update && apt upgradeapt更新升级apt install upx fd-find zip unzip 7zipapt install openssh-server openssh-client sqlite3 lua5.1apt install build-essential安装gcc cc ld makeapt remove upx移除apt search upx搜索apt search php | less空格下一页 q 退出 b上一页apt show upx显示细节- ssh
systemctl enable ssh 设置开机
systemctl disable ssh 取消
systemctl is-enabled ssh 是否开机
systemctl start ssh 启动
systemctl stop ssh 停止
systemctl restart ssh 重启
systemctl status ssh 状态特殊安装
- 安装edit2.0
- zig
curl -sS https://debian.griffo.io/EA0F721D231FDD3A0A17B9AC7808B4DD62C41256.asc
| sudo gpg –dearmor -o /etc/apt/trusted.gpg.d/debian.griffo.io.gpg
添加源
echo “deb https://debian.griffo.io/apt $(lsb_release -sc) main”
| sudo tee /etc/apt/sources.list.d/griffo.list
- lego ssl生成工具
安装rust和golang
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shlinux安装,windows下载后运行rustup update升级
golang使用goup安装https://github.com/thinkgos/goup-rs/goup initecho '. "$HOME/.goup/env"' >> ~/.bashrclinux安装后初始化
goup search 查找版本
goup list 已安装版本
goup install 1.21 安装
goup use 切换版本
goup rm 删除
goup cache show 缓存
goup self update 自更新redis
- 安装redis
sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg –dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo “deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main” | sudo tee /etc/apt/sources.list.d/redis.list
apt install redis
systemctl enable redis-server
systemctl start redis-server
redis.cli -v 检测版本
redis.cli 客户端 redis.cli -h 127.0.0.1 -p 6380
ps -ef | grep redis-server 查看状态msedit /var/snap/redis/common/etc/redis/redis.conf配置/var/snap/redis/common/var/lib/redis/dump.rdb 备份文件
bind 0.0.0.0 远程登陆
protected-mode no
requirepass 123456- frankenphp
sudo curl -fsSL https://key.henderkes.com/static-php.gpg -o /usr/share/keyrings/static-php.gpg && \ echo "deb [signed-by=/usr/share/keyrings/static-php.gpg] https://deb.henderkes.com/ stable main" | sudo tee /etc/apt/sources.list.d/static-php.list && \ sudo apt install frankenphpapt install php-zts-redissystemctl start frankenphpapt install pie-zts安装caddy
caddy validate --config /etc/caddy/CaddyfileCaddyfilecurl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy -y systemctl restart caddy msedit /etc/caddy/Caddyfilehttp://127.0.0.1:9000 http://localhost:9000 { root * /home/rocky/html file_server browse reverse_proxy localhost:3000 }树莓派3b+为例 ubuntu24.04
Raspberry Pi 3 Model B Plus Rev 1.3 1G内存16G存储`
ubuntu 默认账号密码都是ubuntu
设置wifi
sudo nano /etc/netplan/50-cloud-init.yaml Ctrl+O Ctrl+X
network:
version: 2
wifis:
wlan0:dhcp4: true optional: true access-points: "home network": password: "123456789"
sudo passwd root 启用root
vi /etc/ssh/sshd_config
su -
sudo nano /etc/ssh/sshd_config.d/50-cloud-init.conf
PasswordAuthentication yes
PubkeyAuthentication yes
sudo systemctl restart ssh
nmcli radio wifi on 启用wifi
nmcli dev wifi list 扫描wifi
nmcli –ask dev wifi connect 3G
lshw查看硬件信息
apt install -y zram-tools 安装zram
echo ‘SIZE=1024’ | sudo tee /etc/default/zramswap
echo ‘PRIORITY=100’ | sudo tee -a /etc/default/zramswap
echo ‘ALGORITHM=lz4’ | sudo tee -a /etc/default/zramswap
sudo systemctl restart zramswap
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo ‘/swapfile none swap sw 0 0’ | sudo tee -a /etc/fstab
1G内存主机
sudo swapoff /swapfile
sudo rm /swapfile
sudo fallocate -l 256M /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo ‘/swapfile none swap sw 0 0’ | sudo tee -a /etc/fstab
sudo nano /etc/default/zramswap #512够了
sudo systemctl restart zramswap
free -h 查看内存
swapon –show 查看zram
nanomq
curl -s https://assets.emqx.com/scripts/install-nanomq-deb.sh | sudo bash
sudo apt-get install nanomq
cat > /etc/systemd/system/nanomq.service <<EOF
[Unit]
Description=NanoMQ Broker
After=network.target
[Service]
ExecStart=/usr/local/bin/nanomq start
Restart=always
RestartSec=3
User=root
[Install]
WantedBy=multi-user.target
EOFsystemctl daemon-reload
systemctl enable nanomq
systemctl start nanomq
nano /usr/local/bin/nanomq.conf
mqtt = {
max_packet_size = 1KB # NanoMQ 可接收和发送的最大包大小。
max_mqueue_len = 2048 # 等待确认窗口队列的最大长度。
retry_interval = 10s # QoS 1/2 消息投递的重试间隔。
keepalive_multiplier = 1.25 # MQTT keepalive 超时的乘数。
property_size = 32 # MQTT 用户最大属性长度。
}
listeners.tcp {
bind = "0.0.0.0:1883" # 绑定 1883 端口
}
listeners.ws {
bind = "0.0.0.0:1885/mqtt" # 绑定 1885 端口
}
http_server = {
port = 1884 # HTTP 服务器端口
ip_addr = "0.0.0.0" # HTTP 服务器 Address
limit_conn = 32 # NanoMQ 可以处理的最大未完成请求数
username = "admin" # 用户名
password = "12345678" # 密码
max_body = 65535 # 最大 HTTP Body
auth_type = "basic"
}
auth {
allow_anonymous = true # 允许匿名登录
no_match = allow # 没有 ACL 规则匹配情况下的默认操作
deny_action = ignore # ACL 检查拒绝情况下的默认操作
password = {include "/usr/local/bin/nanomq.passwd"} # 密码存储文件路径
}nano /usr/local/bin/nanomq.passwd #密码 admin:123 每行
chmod 600 /usr/local/bin/nanomq.passwd
systemctl restart nanomq
ubuntu24.04
- 修改软件源
/etc/apt/sources.list
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
dnf
rpm -ivh package_name.rpmrpm安装dnf history list | grep Install列出最近安装软件dnf info golang前者简介查看信息后者详细信息dnf upgrade与dnf update功能相同dnf install upx支持install,search,removednf list installed已安装软件dnf install epel-release -y安装扩展dnf clean all && dnf makecache生成缓存dnf install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm -y免费仓库sudo dnf makecache添加源后刷新dnf list --showduplicates nginx列出可用版本dnf install nginx-2:1.28.0-1.el10.ngxdnf install sqlite luadnf install gcc gcc-c++ make binutils glibc-devel zlib-devel openssl-devel autoconf automake libtool cmakednf install nodejsnode -vnpm -vdnf install postgresql postgresql-server5432端口sudo postgresql-setup --initdb初始化vi /var/lib/pgsql/data/pg_hba.conf添加host all all 0.0.0.0/0 scram-sha-256vi /var/lib/pgsql/data/postgresql.conf配置文件listen_addresses = '*' # 默认为 'localhost'远程port = 5432端口修改sudo -i -u postgres切换账号psql
systemctl start postgresql 启动dnf install mysql8.4 mysql8.4-servervi /etc/my.cnf.d/mysql-server.cnf配置port = 3306注意权限不能修改,/etc/my.cnf也不能改权限,默认密码为空bind-address = 0.0.0.0允许远程mysql -u root -p -P 3307登陆自定义端口systemctl start mysqld启动dnf install btop zip unzip 7zip git wget openssh-server openssh-clientssystemctl start sshd启动
通用
apt install upx fd-find zip unzip 7zip sqlite3 btop nginx mysql-server
software-properties-common ca-certificates apt-transport-https
apt install -y postgresql-18 postgresql-client-18
linux ubuntu软件
edge XTerminal
单文件安装 mv edit /usr/local/bin/ && chmod +x /usr/local/bin/edit
最后编辑:Yoby 更新时间:2026-05-04 23:08