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 yessystemd
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
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 状态特殊安装 msedit go rustup
snap install mseditsnap install go --classic特殊安装golangsnap refresh go更新snap install rustup --classic安装rustrustup 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 ~/.bashrcsnap install zig --classic --betaubuntusnap install legossl生成工具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 frankenphpapt install php-zts-redissystemctl start frankenphpapt install pie-zts安装caddy
安装到/usr/local/bincaddy validate --config /usr/local/bin/Caddyfileuseradd -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.targetCaddyfile
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.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
作者:Yoby 创建时间:2024-12-04 18:18
最后编辑:Yoby 更新时间:2026-01-10 02:48
最后编辑:Yoby 更新时间:2026-01-10 02:48