rhel/centos/rocky/fedora/aliyun (dnf,yum,rpm,snap)

ubuntu/debian (apt,deb,snap)

系统

  • cat /etc/os-release 查看系统信息
  • hostnamectl 查看版本信息
  • df -h 磁盘空间使用情况
  • free -h 查看内存使用状况
  • lscpu cpu相关
  • reboot 重启
  • halt 关机
  • clear CTRL+L 清屏
  • nohup frpc -c frpc.toml & 后台启动

    软件版本

  • ldd --version 查看glibc版本
  • git -v查看git版本
  • ssh -V 判断是否安装客户端

    目录文件操作

  • cd ~ 进入root目录
  • whereis redis-cli 查看路径
  • pwd 当前路径
  • ls ls -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 - 切换到root
  • su postgres 切换用户postgres
  • useradd postgres 添加用户
  • userdel postgres 删除用户
  • usermod -a -G groupname username 添加用户到组
  • groupadd postgres groupdel 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 查看ip
  • route -n 查看路由
  • ping ping网址
  • curl http://localhost
  • wget -O file url下载

    分区

  • dd if=/dev/zero of=/swap1 bs=1M count=2048 创建交换分区
  • mkswap /swap1创建
  • swapon /swap1启用

    压缩解压

  • tar -xzvf 1.tar.gz gz解压
  • tar -czvf 1.tar.gz 1.c gz压缩文件夹或文件
  • zip -r 1.zip /home zip文件压缩备份 后面是压缩某个文件夹绝对路径
  • unzip 1.zip 解压zip
  • 7z a 1.7z ./html 压缩支持多个文件夹 有些系统7za
  • 7z x 1.7z 解压当前目录 7z x 1.7z -o./qq到指定qq目录

    防火墙

  • ufw enable && ufw default deny 启动防火墙
  • ufw status 列出所有
  • ufw allow 9999 ufw allow 22/tcp 允许端口
  • ufw delete allow 9999 删除端口
  • ufw version

    vi或vim操作配置

  • ESC :q 退出 | :wq! 退出并保存| 按I键 进入输入模式
  • echo $PATH 类似win的path
  • export CGO_ENABLED=1 导入变量
  • export CC=/usr/local/musl/bin/musl-gcc 编译musl-gcc
  • vi /etc/profile末尾加入 export PATH=$PATH:/root/bin多个用:分割
  • source /etc/profile 立即生效上面修改
  • vi /etc/init.wsl 自动启动文件
  • vi /etc/ssh/sshd_config 编辑此文件内容如下Port 22 PermitRootLogin yes

    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服务

    编译程序

  • ./configure
  • make && make install

nginx

  • apt install nginx dnf install nginx
    systemctl start nginx
    systemctl stop nginx
    systemctl reload nginx
    systemctl restart nginx
    systemctl enable nginx
    systemctl status nginx
    curl http://localhost 测试
    nginx -V 查看模块
    nginx -t 查看配置
    /etc/nginx/conf.d/ 配置文件 默认 root /usr/share/nginx/html 默认网站目录
    禁止缓存
    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;
    vi /etc/yum.repos.d/nginx.repo 添加官方源
    [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.key
    ubuntu添加源
    curl -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/99nginx

    mysql

  • apt install mysql-server
  • mysql_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.cnf 127.0.0.1改成0.0.0.0
  • systemctl restart mysql 重启
  • systemctl status mysql 查看状态
    mysql -V
    mysqldump -u root -p testdb > aa.sql备份数据库
    mysqldump -u root -p testdb | gzip > aaa.sql.gz

    pgsql

    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.list
    apt-cache search postgresql | grep postgresql-[0-9]查看可选版本
    apt install -y postgresql-18 postgresql-client-18
    psql -V
    sudo -u postgres psql 修改密码 \q 退出
    ALTER USER postgres WITH PASSWORD 'pgsql'; 用户postgres
    systemctl 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 md5
    psql -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-common
    apt 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-gd
    apt install -y php7.2 php7.2-fpm php7.2-cli php7.2-common
    apt 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-gd
    php -v php -m 查看版本和模块
    apt install -y software-properties-common
    sudo add-apt-repository ppa:ondrej/php && apt update
    systemctl status php8.3-fpm
    systemctl restart php8.3-fpm
    systemctl 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 -y
    apt autoclean -y

    snap安装

  • dnf install snapd -y
  • systemctl enable --now snapd.socket
  • ln -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

  • grep -i "install" /var/log/apt/history.log查看安装列表
  • apt install ./package_name.deb
  • apt update && apt upgrade apt更新升级
  • apt install upx fd-find zip unzip 7zip
  • apt install openssh-server openssh-client sqlite3 lua5.1
  • apt install build-essential 安装gcc cc ld make
  • apt 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 状态

    特殊安装 msedit go rustup

  • snap install msedit
  • snap install go --classic 特殊安装golang
    snap refresh go 更新
  • snap install rustup --classic 安装rust
    rustup install stable 初始化
    rustup update 更新
    root/.bashrc末尾添加,镜像源
    export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
    export RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup
    source ~/.bashrc
  • snap install zig --classic --beta ubuntu
  • snap install lego ssl生成工具

    redis

  • snap install redis 安装redis
    redis.cli -v 检测版本
    redis.cli 客户端 redis.cli -h 127.0.0.1 -p 6380
    snap start redis | snap stop redis | snap restart redis
    snap services redis
    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 frankenphp
    apt install php-zts-redis
    systemctl start frankenphp
    apt install pie-zts

    安装caddy

    安装到/usr/local/bin
    caddy validate --config /usr/local/bin/Caddyfile
    useradd -r -s /sbin/nologin caddy 创建用户
    systemctl start caddy 启动
    systemctl restart caddy 重新
    systemctl status caddy 状态
    systemctl enable caddy 开机启动
    sudo chown -R caddy:caddy /home/caddy/ 设置权限
    vi /etc/systemd/system/caddy.service 创建systemtl
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Wants=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/local/bin/caddy run --environ --config /usr/local/bin/Caddyfile
ExecReload=/usr/local/bin/caddy reload --config /usr/local/bin/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

Caddyfile

http://127.0.0.1:9000 http://localhost:9000 {
        root * /home/rocky/html
        file_server browse
}

树莓派3b+为例 rocky9.2

Raspberry Pi 3 Model B Plus Rev 1.3 1G内存16G存储

rocky rockylinux 默认账号密码
sudo rootfs-expand 安装完后分区
sudo passwd root 启用root
vi /etc/ssh/sshd_config
su -
nmcli radio wifi on  启用wifi
nmcli dev wifi list 扫描wifi
nmcli --ask dev wifi connect 3G
lshw查看硬件信息

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.rpm rpm安装
  • dnf history list | grep Install 列出最近安装软件
  • dnf info golang 前者简介查看信息后者详细信息
  • dnf upgradednf update 功能相同
  • dnf install upx 支持install,search,remove
  • dnf 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.ngx
  • dnf install sqlite lua
  • dnf install gcc gcc-c++ make binutils glibc-devel zlib-devel openssl-devel autoconf automake libtool cmake
  • dnf install nodejs node -v npm -v
  • dnf install postgresql postgresql-server 5432端口
  • sudo postgresql-setup --initdb 初始化
  • vi /var/lib/pgsql/data/pg_hba.conf 添加
    host all all 0.0.0.0/0 scram-sha-256
  • vi /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-server
    vi /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-clients
  • systemctl 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

作者:Yoby  创建时间:2024-12-04 18:18
最后编辑:Yoby  更新时间:2026-01-10 02:48
上一篇:
下一篇: