RHEL/centos/rocky/fedora/aliyun

使用dnf(yum,rpm)支持snap

ubuntu/debian/

使用snap(apt,deb)

系统相关

  • 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 默认12345678端口23
  • 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显示当前活跃(运行中)的服务

    编译程序

  • ./configure
  • make && make install

dnf centos/rocky/阿里云 yum/rpm

  • 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 nodejs node -v npm -v

    postgresql

  • 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 启动
    systemctl restart postgresql重启
    systemctl enable postgresql 开机启动
    systemctl status postgresql 状态

    mysql

  • 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 启动
    systemctl restart mysqld 重启
    sudo systemctl enable mysqld 创建开机启动

    btop 7zip git wget openssh-server

  • dnf install btop zip unzip 7zip git wget openssh-server openssh-clients
    systemctl start sshd 启动 stop 停止
    systemctl restart sshd 重启
    systemctl status sshd 状态
    systemctl enable sshd 设置开机 disable 取消
    systemctl is-enabled sshd 是否开机启动

    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;
    配置php
          listen       8000 ssl;
          server_name  localhost;
            root   /home/html;
           index  index.html index.htm index.php;
    location ~ \.php$ {
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
          }
    配置ssl
    ssl_certificate      /root/nginx/localhost.pem;
        ssl_certificate_key  /root/nginx/localhostkey.pem;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
         ssl_prefer_server_ciphers  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

    安装 GCC,make,binutils

  • dnf install gcc gcc-c++ make binutils glibc-devel zlib-devel openssl-devel autoconf automake libtool cmake

    snap

  • dnf install snapd -y
  • systemctl enable --now snapd.socket
  • sudo ln -s /var/lib/snapd/snap /snap 经典模式
  • sudo systemctl start snapd开启
  • sudo systemctl enable snapd开机启动项

    snap ubuntu/Debian apt/deb

  • 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
  • apt remove upx 移除
  • apt search upx 搜索
  • apt show upx 显示细节
  • snap install snap-store-proxy 加速,一般不需要
  • snap find qq # 搜索
  • snap list # 查看已安装列表
  • snap refresh # 更新所有包
  • snap remove msedit # 卸载软件
  • ssh
    systemctl enable ssh 设置开机 disable 取消
    systemctl is-enabled ssh 是否开机启动
    systemctl start ssh 启动 stop 停止
    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 更新

    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 备份文件

    手动安装caddy

    安装到/usr/local/bin
    caddy validate --config /usr/local/bin/Caddyfile
    useradd -r -s /sbin/nologin caddy 创建用户
    systemctl status caddy.service 检测失败原因
    systemctl daemon-reload 重载systed
    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
[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
}