标签归档:Debian

Debian 安装 killall 命令

昨天部署一台 Debian 12 服务器,发现竟然没有killall命令,那么就来安装一下吧。

执行apt install psmisc命令安装 psmic 包,这个包的官方仓库是 https://gitlab.com/psmisc/psmisc ,描述是“一组使用 proc 文件系统的小型实用程序”,包含以下六个实用工具:

  • fuser – 使用文件或套接字识别进程
  • killall – 根据名称终止进程,例如 killall -HUP named
  • prtstat – 打印进程的统计信息
  • pslog – 打印进程的日志路径
  • pstree – 以树的形式显示当前正在运行的进程
  • peekfd – 显示通过文件描述符传输的数据

安装完成后,就可以使用killall命令根据进程名称终止进程了。

后记:

2025年了,时间仿佛飞一般,一年转瞬即逝,新的一年已经到来,等过完了春节就到了阳历二月,再有十个月就是 2026 年了。所以,不要蹉跎岁月,有什么想法要抓紧时间去干。

查看Debian开机启动项

查看所有启用的服务:

systemctl list-unit-files --type=service

该命令会列出所有服务的启动状态,其中标记为 enabled 的服务会在开机时自动启动。

查看当前正在运行的服务:

systemctl list-units --type=service

这个命令会列出当前正在运行的服务,已启动的服务会标记为 running。

systemctl list-unit-files --type=service 输出 列表太长,如果不想看整个列表,只想简单地查看启用的服务,可以运行以下命令:

systemctl list-unit-files --type=service | grep enabled

这个命令会列出所有启用(enabled)的服务,只有那些会在系统启动时自动启动的服务会被显示。

查看当前运行的服务

systemctl list-units --type=service --state=running

这个命令会显示当前正在运行的服务,但它不会直接列出所有已配置为开机启动的服务。它只会列出系统启动后当前处于运行状态的服务。

检查特定服务是否设置为开机启动

systemctl is-enabled <service-name>

例如,要查看 ssh 服务是否在开机时启动:

systemctl is-enabled ssh

如果返回 enabled,则表示该服务已配置为开机启动。

使用 grep 筛选开机启动的服务(更简洁的命令)

systemctl list-unit-files --type=service | awk '$2=="enabled" {print $1}'

这个命令会只输出那些标记为 enabled 的服务名称,避免显示其他无关的服务信息。

最后,也可以查看/etc/init.d/目录(SysVinit 脚本,这个适合于老旧的系统,新系统中也会有这个目录,但不太推荐使用了

ls /etc/init.d/

查看Debian内核版本

查看已安装的内核列表:

dpkg --list | grep linux-image

查看当前使用中的内核版本:

uname -r

如果有新内核,需要重启系统,重新启动后,会自动使用最新版本的内核。

最好不要折腾内核,稳定性第一!

查看kexec是否安装 :

dpkg -l | grep kexec-tools

安装 :

apt install kexec-tools

正常来说不需要这个东西,感觉没什么用,都要重启了,也不差那几秒。所以说,更新的时候如果有新内核,提示是否使用kexec,那么选No就行了,正常重启即可。

Debian12安装PHP7.4

请注意:PHP7.4已经于2022年11月28日停止维护。

安装sury源:

#!/bin/sh
# To add this repository please do:
if [ "$(whoami)" != "root" ]; then
    SUDO=sudo
fi
${SUDO} apt-get update
${SUDO} apt-get -y install lsb-release ca-certificates curl
${SUDO} curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
${SUDO} dpkg -i /tmp/debsuryorg-archive-keyring.deb
${SUDO} sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
${SUDO} apt-get update

安装PHP7.4:

apt install -y php7.4-fpm php7.4-mysql php7.4-mbstring php7.4-curl php7.4-xml php7.4-imagick php7.4-zip php7.4-gd php7.4-intl php7.4-bcmath

Debian+Nginx+PHP HTTPS配置模板

Nginx+PHP+HTTPS的配置模板,如果要部署其它网站,可以基于此进行修改:

# 处理 HTTP 请求,所有请求都重定向到 https://www.jsdd.net
server {
    listen 80;
    server_name jsdd.net www.jsdd.net;  # 同时匹配带 www 和不带 www 的域名

    # 所有请求都重定向到 https://www.jsdd.net
    return 301 https://www.jsdd.net$request_uri;
}

# 处理不带 www 的 HTTPS 请求,重定向到带 www 的域名
server {
    listen 443 ssl http2;
    server_name jsdd.net;  # 不带 www 的域名

    ssl_certificate /etc/nginx/ssl/www.jsdd.net.pem;  # 证书路径
    ssl_certificate_key /etc/nginx/ssl/www.jsdd.net.key;  # 证书路径

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
    ssl_ecdh_curve secp384r1;
    ssl_session_timeout 10m;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;
    ssl_stapling on;
    ssl_stapling_verify on;

    # 重定向所有不带 www 的 HTTPS 请求到 www.jsdd.net
    return 301 https://www.jsdd.net$request_uri;
}

# 处理带 www 的 HTTPS 请求
server {
    listen 443 ssl http2;
    root /var/www/jsdd.net; # 确保这里是正确的根目录路径
    index index.html index.htm index.php index.nginx-debian.html;

    server_name  www.jsdd.net;
    client_max_body_size 20m;

    ssl_certificate /etc/nginx/ssl/www.jsdd.net.pem; # 确保证书路径正确
    ssl_certificate_key /etc/nginx/ssl/www.jsdd.net.key; # 确保证书路径正确

    #加上TLSv1,HTTPS检测会报PCI DSS不合规
    ssl_protocols  TLSv1.2 TLSv1.3;# Requires nginx >= 1.13.0 else use TLSv1.2
    ssl_prefer_server_ciphers on;
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
    ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
    ssl_session_timeout 10m;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off; # Requires nginx >= 1.5.9
    ssl_stapling on; # Requires nginx >= 1.3.7
    ssl_stapling_verify on; # Requires nginx => 1.3.7

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }
}

Debian+Nginx+PHP配置模板

Nginx+PHP+HTTP的配置模板,如果要部署其它网站,可以基于此进行修改:

server {
    listen 80;
    root /var/www/www.example.com;
    # Add index.php to the list if you are using PHP
    index index.html index.htm index.php index.nginx-debian.html;

    server_name www.example.com example.com;

    client_max_body_size 20m;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }
}

Debian配置系统时区

运行命令:

dpkg-reconfigure tzdata

根据需要选择,很简单。

dpkg-reconfigure tzdata 是一个用于重新配置系统时区的命令。

在基于 Debian 的 Linux 系统(如 Ubuntu)中,tzdata 是一个提供时区信息的软件包。通过运行 dpkg-reconfigure tzdata,你可以重新设置系统的时区,以确保系统显示的时间是正确的。

设置完成后,命令会显示类似以下的信息:

Current default time zone: 'Asia/Shanghai'
Local time is now:      Fri Nov 29 18:45:00 CST 2024
Universal Time is now:  Fri Nov 29 10:45:00 UTC 2024

可以执行date命令以查看当前时间。

Debian 开启 BBR 算法

1、修改系统变量

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf

2、保存生效

sysctl -p

3、查看内核是否已开启BBR

sysctl net.ipv4.tcp_available_congestion_control

显示以下即已开启:

net.ipv4.tcp_available_congestion_control = bbr cubic reno

4、查看BBR是否启动

lsmod | grep bbr

显示以下即启动成功:

tcp_bbr                20480  1

Debian12 安装 PHP8.3

当前 Debian12 官方源中带的 PHP 版本是8.2,而 PHP8.2 的 Active Support 到今年年底(31 Dec 2024),所以直接装8.3吧,可以用的时间长一点。

首先安装sury源

#!/bin/sh
# To add this repository please do:
if [ "$(whoami)" != "root" ]; then
    SUDO=sudo
fi
${SUDO} apt-get update
${SUDO} apt-get -y install lsb-release ca-certificates curl
${SUDO} curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
${SUDO} dpkg -i /tmp/debsuryorg-archive-keyring.deb
${SUDO} sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
${SUDO} apt-get update

注意,如果安装sury源时报错: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY B188E2B695BD4743,意思是系统缺少sury源的公钥。只要把公钥下载到系统就可以了,执行以下命令添加公钥:

wget -qO /etc/apt/trusted.gpg.d/sury-php.gpg https://packages.sury.org/php/apt.gpg

公钥添加完成后,执行apt update刷新包列表即可。

然后执行以下命令安装PHP8.3:

apt install -y php8.3-fpm php8.3-mysql php8.3-mbstring php8.3-curl php8.3-xml php8.3-imagick php8.3-zip php8.3-gd php8.3-intl php8.3-bcmath

如果需要支持 Laravel 框架,那么最后一个 bcmath 扩展是必须的。

Debian11 升级 Debian12

今天通过博客园首页链接购买了37块钱的天翼云,发现 Debian 最新版本只到11,那么就来升级一下吧。

1、更新当前系统apt updateapt full-upgrade,更新完后发现有一个包没有被升级0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.,执行apt list --upgradable -a看了一下,输出如下:

root@vm:~# apt list --upgradable -a
Listing... Done
base-files/oldstable 11.1+deb11u11 amd64 [upgradable from: 11.1+deb11u1]
base-files/now 11.1+deb11u1 amd64 [installed,upgradable to: 11.1+deb11u11]

应该是一个涉及核心系统的包,手动升级一下吧: apt-get install base-files

2、更新完成后,更换 Debian12 的源,首先备份当前源 mv /etc/apt/sources.list /etc/apt/sources.list.old,然后写入 Debian12 的源,这里用的是清华的源:

cat > /etc/apt/sources.list << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
EOF

3、继续更新系统apt updateapt full-upgrade,期间会有一些提示信息,根据需要选择。

更新完后,查看系统版本cat /etc/debian_version, 我这里显示的是12.7,嗯,最新版本 Debian 已经更新好了。

Debian 大版本升级还是一如既往的丝滑,从来没有让我失望过👍💖。

注:本文始发于我的博客园 https://www.cnblogs.com/art ,之后重新发于本站。

Debian 更换国内清华源

1、备份原文件 mv /etc/apt/sources.list /etc/apt/sources.list.old

2、写入新源,以下是 Debian 11 的:

cat > /etc/apt/sources.list << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
 
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
 
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
 
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
EOF

如果是 Debian 12:

cat > /etc/apt/sources.list << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
EOF

注:

deb 指向的是编译好的二进制软件包。
deb-src 指向的是软件的源代码包,可以使用apt source命令下载软件的源代码并自行编译。

注:本文始发于我的博客园 https://www.cnblogs.com/art ,之后重新发于本站。