RHEL/centos/rocky/fedora/aliyun
使用dnf(yum,rpm)支持snap
ubuntu/debian/
使用snap(apt,deb)
系统相关
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 默认12345678端口23su -切换到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显示当前活跃(运行中)的服务编译程序
./configuremake && make install
dnf centos/rocky/阿里云 yum/rpm
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 nodejsnode -vnpm -vpostgresql
dnf 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-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-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 启动
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/htmlvi /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; 配置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;[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 cmakesnap
dnf install snapd -ysystemctl enable --now snapd.socketsudo ln -s /var/lib/snapd/snap /snap经典模式sudo systemctl start snapd开启sudo systemctl enable snapd开机启动项snap ubuntu/Debian apt/deb
apt install ./package_name.debapt update && apt upgradeapt更新升级apt install upx fd-find zip unzip 7zipapt install openssh-server openssh-client sqlite3apt 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 mseditsnap install go --classic特殊安装golangsnap refresh go更新snap install rustup --classic安装rustrustup 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/bincaddy validate --config /usr/local/bin/Caddyfileuseradd -r -s /sbin/nologin caddy创建用户systemctl status caddy.service检测失败原因systemctl daemon-reload重载systedsystemctl 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.targetCaddyfile
http://127.0.0.1:9000 http://localhost:9000 {
root * /home/rocky/html
file_server browse
}