RHEL系Linux更新内核

ELRepo 简介

项目主页:http://elrepo.org

Enterprise Linux 软件包的 RPM 存储库。ELRepo 支持 Red Hat Enterprise Linux (RHEL) 及其衍生产品,如CentOS Linux、AlmaLinux 和 Rocky Linux。

启用 ELRepo

从 CentOS 8 开始,ELRepo 已经加入到官方软件仓库中,名称为 “elrepo-release”。

AlmaLinux 和 Rocky Linux 同样适用。

启用 ELRepo 只需要执行命令:

dnf -y install elrepo-release

升级内核

查询 ELRepo 中的 kernel 版本

yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available --showduplicates #查看所有版本

kernel-ml 中的 ml 是英文 “mainline stable” 的缩写,elrepo-kernel 中列出来的是最新的稳定主线版本。
kernel-lt 中的 lt 是英文 “long term support” 的缩写,elrepo-kernel 中列出来的长期支持版本。

安装 kernel

yum --disablerepo="*" --enablerepo=elrepo-kernel install kernel-ml kernel-ml-core kernel-ml-devel kernel-ml-modules  kernel-ml-modules-extra

慎重装kernel-ml-headers包,会和发行版的kernel-headers包冲突

Error:
 Problem: package kernel-ml-headers-6.16.6-1.el8.elrepo.x86_64 from elrepo-kernel conflicts with kernel-headers < 6.16.6-1.el8.elrepo provided by kernel-headers-4.18.0-553.34.1.el8_10.x86_64 from @System
  - cannot install the best candidate for the job
  - problem with installed package kernel-headers-4.18.0-553.34.1.el8_10.x86_64

elrepo官方提示:

There is no need to install the kernel-lt-headers package. It is only necessary if you intend to rebuild glibc and, thus, the entire operating system. If there is a need to have the kernel headers installed, you should use the current distributed kernel-headers package as that is related to the current version of glibc. When you see a message like “your kernel headers for kernel xxx cannot be found …”, you most likely need the kernel-lt-devel package, not the kernel-lt-headers package.

kernel-headers包是给用户态程序用的,个人理解为类似libc标准库里的*unix规范接口函数,不同版本内核间相当稳定,所以使用发行版的即可。
kernel-devel包是给开发内核态程序\内核模块用的,不通版本内核间就有差异,所以需要单独装。

所以常规仅仅是使用新版本内核,不需要装kernel-ml-headers,保持使用发行版的kernel-headers,而且升级发行版的kernel版本时kernel-headers也可能不会一起更新,kernel-headers在需要时才会更新。

发行版源的其他软件,都依赖发行版的kernel-headers,忽略冲突安装可能造成其他软件安装失败,https://www.rockylinux.cn/notes/rocky-linux-9-nei-he-sheng-ji-zhi-6.html

查询安装的 kernel 包

rpm -qa|grep kernel

查看和设置默认启动项

grubby 是一个命令行工具,用于更新和显示有关 grub2 和 zipl 引导加载程序的配置文件的信息。它主要设计用于安装新内核并需要查找有关当前引导环境的信息的脚本。同时也可以对启动内核的各项信息参数进行修改。

在 CentOS 8 在已经自带该命令,如果没有通过 yum install grubby 来安装即可。

查看当前的默认启动内核:

grubby --default-kernel
/boot/vmlinuz-5.15.4-1.el8.elrepo.x86_64

查看系统安装的全部内核:

grubby --info=ALL

index=0
kernel="/boot/vmlinuz-5.15.4-1.el8.elrepo.x86_64"
args="ro crashkernel=auto net.ifnames=0 $tuned_params"
root="UUID=56c34ece-6010-480e-aeac-dea98b8ffcd3"
initrd="/boot/initramfs-5.15.4-1.el8.elrepo.x86_64.img $tuned_initrd"
title="Rocky Linux (5.15.4-1.el8.elrepo.x86_64) 8.5 (Green Obsidian)"
id="032ed95ba9c0471381bbb6b416eff523-5.15.4-1.el8.elrepo.x86_64"
index=1
kernel="/boot/vmlinuz-4.18.0-348.2.1.el8_5.x86_64"
args="ro crashkernel=auto net.ifnames=0 $tuned_params"
root="UUID=56c34ece-6010-480e-aeac-dea98b8ffcd3"
initrd="/boot/initramfs-4.18.0-348.2.1.el8_5.x86_64.img $tuned_initrd"
title="Rocky Linux (4.18.0-348.2.1.el8_5.x86_64) 8.5 (Green Obsidian)"
id="032ed95ba9c0471381bbb6b416eff523-4.18.0-348.2.1.el8_5.x86_64"
index=2
kernel="/boot/vmlinuz-4.18.0-348.el8.x86_64"
args="ro crashkernel=auto net.ifnames=0 $tuned_params intel_iommu=on"
root="UUID=56c34ece-6010-480e-aeac-dea98b8ffcd3"
initrd="/boot/initramfs-4.18.0-348.el8.x86_64.img $tuned_initrd"
title="AlmaLinux (4.18.0-348.el8.x86_64) 8.5 (Arctic Sphynx)"
id="032ed95ba9c0471381bbb6b416eff523-4.18.0-348.el8.x86_64"
index=3
kernel="/boot/vmlinuz-0-rescue-032ed95ba9c0471381bbb6b416eff523"
args="ro crashkernel=auto net.ifnames=0"
root="UUID=56c34ece-6010-480e-aeac-dea98b8ffcd3"
initrd="/boot/initramfs-0-rescue-032ed95ba9c0471381bbb6b416eff523.img"
title="AlmaLinux (0-rescue-032ed95ba9c0471381bbb6b416eff523) 8.5 (Arctic Sphynx)"
id="032ed95ba9c0471381bbb6b416eff523-0-rescue"

查看特定内核的具体信息:

grubby --info=/boot/vmlinuz-4.18.0-348.el8.x86_64
index=1
kernel="/boot/vmlinuz-4.18.0-348.el8.x86_64"
args="ro crashkernel=auto net.ifnames=0 $tuned_params"
root="UUID=56c34ece-6010-480e-aeac-dea98b8ffcd3"
initrd="/boot/initramfs-4.18.0-348.el8.x86_64.img $tuned_initrd"
title="AlmaLinux (4.18.0-348.el8.x86_64) 8.5 (Arctic Sphynx)"
id="032ed95ba9c0471381bbb6b416eff523-4.18.0-348.el8.x86_64"

设置新的默认启动内核:

使用路径来指定内核,可以使用 –set-default=kernel-path

grubby --set-default=/boot/vmlinuz-4.18.0-348.el8.x86_64
The default is /boot/loader/entries/032ed95ba9c0471381bbb6b416eff523-4.18.0-348.el8.x86_64.conf with index 1 and kernel /boot/vmlinuz-4.18.0-348.el8.x86_64

grubby --default-kernel
/boot/vmlinuz-4.18.0-348.el8.x86_64

使用 index 来指定内核,则使用 –set-default-index=entry-index

grubby --set-default-index=1
The default is /boot/loader/entries/032ed95ba9c0471381bbb6b416eff523-4.18.0-348.el8.x86_64.conf with index 1 and kernel /boot/vmlinuz-4.18.0-348.el8.x86_64

grubby --default-kernel
/boot/vmlinuz-4.18.0-348.el8.x86_64

重启后生效

reboot

删除旧内核(可选)

从启动项中删除旧内核

grubby --remove-kernel=/boot/vmlinuz-4.18.0-348.el8.x86_64

删除旧内核文件

# 删除旧内核
yum remove kernel-4.18.0 kernel-core-4.18.0 kernel-modules-4.18.0 kernel-devel-4.18.0
# 需要注意,是否同时删除一些依赖包。

Kernel相关的RPM包说明

kernel-core
提供内核的二进制镜像、所有与 initramfs相关的对象来引导系统,以及确保核心功能的最小内核模块数量。

kernel-modules
提供 kernel-core 中不存在的其余内核模块。

kernel-modules-extra
为罕见硬件提供内核模块。默认禁用模块的加载。

kernel-debug
提供了启用了许多调试选项的内核,以便进行内核诊断,以降低性能为代价。

kernel-tools
提供了操作 Linux 内核和支持文档的工具。

kernel-devel
提供了内核标头和 makefile,来足以针对 kernel 软件包构建模块。

kernel-abi-stablelists
提供与 RHEL 内核 ABI 相关的信息,包括外部 Linux 内核模块所需的内核符号列表和 yum 插件以协助执行。

kernel-headers
包括指定 Linux 内核和用户空间库以及程序间接口的 C 标头文件。头文件定义构建大多数标准程序所需的结构和常量。

安装ELRepo历史版本内核

官方的elrepo, lt和ml都只有当前版本的包。

如果要指定安装指定版本的内核,可以从这里https://mirrors.coreix.net/elrepo-archive-archive/kernel/下载RPM包。

例如rockylinux8目前了mainline是6.x,安装高版本的5.x:

wget -c https://mirrors.coreix.net/elrepo-archive-archive/kernel/el8/x86_64/RPMS/kernel-ml-5.19.9-1.el8.elrepo.x86_64.rpm
wget -c https://mirrors.coreix.net/elrepo-archive-archive/kernel/el8/x86_64/RPMS/kernel-ml-core-5.19.9-1.el8.elrepo.x86_64.rpm
wget -c https://mirrors.coreix.net/elrepo-archive-archive/kernel/el8/x86_64/RPMS/kernel-ml-devel-5.19.9-1.el8.elrepo.x86_64.rpm
wget -c https://mirrors.coreix.net/elrepo-archive-archive/kernel/el8/x86_64/RPMS/kernel-ml-modules-5.19.9-1.el8.elrepo.x86_64.rpm
wget -c https://mirrors.coreix.net/elrepo-archive-archive/kernel/el8/x86_64/RPMS/kernel-ml-modules-extra-5.19.9-1.el8.elrepo.x86_64.rpm

# rpm -ivh --oldpackage kernel-ml-*
rpm -ivh kernel-ml-*

文章参考

https://sysin.org/blog/centos-8-upgrade-kernel/

阅读全文

本地Lambda函数几行代码实现MCP Server

文章视频教程: https://www.bilibili.com/video/BV1wWd8YNEZY/?vd_source=e14a954d1c7739b152548d58bf125603

MCP+Lambda

MCP服务器充当MCP客户端与Lambda函数之间的桥梁,使生成式AI模型能够访问和运行Lambda函数作为工具。

社区项目 https://github.com/danilop/MCP2Lambda

但是目前MCP在安全方面还比较弱,所以社区MCP工具基本都是本地工具,Lambda能不能也本地部署。

Refunc是基于K8S的一个本地化的Lambda平台,可以实现本地部署Lambda函数。

MCP+Refunc

Refunc社区跟进MCP发展,实现了任意函数通过MCP开放调用。

https://github.com/refunc/mcp-server

部署 Refunc

refunc-system 命名空间下部署所有 Refunc 组件。

kubectl apply -f https://raw.githubusercontent.com/refunc/mcp-server/refs/heads/main/deploy/play-all-in-one.yaml

接着,将 Refunc 服务代理到本地。

kubectl port-forward svc/aws-api 8000:http --address 0.0.0.0 -n refunc-system
kubectl port-forward svc/mcp-server 8001:http --address 0.0.0.0 -n refunc-system

注意:演示部署中的数据是非持久化的。

创建函数

使用 refunc-cli 创建一个函数。

pip install -U refunc-cli
mkdir mcp-demo && cd mcp-demo
rfctl init

main.py 中编写任意代码,演示将回显一条问候消息。

AWS_DEFAULT_ENDPOINT=http://127.0.0.1:8000 rfctl create

注意:您需要一个 Python 3 环境。

创建 MCP 端点

编辑 lambda.yaml 并粘贴以下代码。

metadata:
  name: mcp-demo
  namespace: refunc-system
spec:
  build:
    source: .
    manifest: requirements.txt
    language: python
    architecture: x86_64
  handler: main.lambda_handler
  timeout: 120
  runtime: "python3.10"
  concurrency: 1
  environment:
    ENV_TEST: TEST
#  url:
#    cors:
#      allowCredentials: true
#      allowHeaders: "*"
#      allowMethods: "*"
#      allowOrigins: "*"
#      exposeHeaders: "*"
#      maxAge: 300
  events:
    # - name: hourly
    #   type: cron
    #   mapping:
    #     cron: 0 * * * *
    #     location: Asia/Shanghai
    #     args:
    #       var1: value1
    #     saveLog: false
    #     saveResult: false
    - name: mcp
      type: mcp
      mapping:
        args:
          token: mcp-demo
          tools:
            - name: echo-hello
              desc: Echo a hello msg
              schema:
                type: object
                properties: {}
                required: []
        saveLog: false
        saveResult: false

接下来,运行以下命令更新配置:

AWS_DEFAULT_ENDPOINT=http://127.0.0.1:8000 rfctl update-config

演示的 MCP SSE 端点为:http://127.0.0.1:8001/refunc-system/mcp-demo/test/mcp-demo/sse

Refunc MCP SSE URL 路径格式为:/namespace/<token-secret-name>/<token>/<func-name>/sse

Refunc MCP 事件规范

- name: mcp
  type: mcp # 事件类型必须为 mcp。
  mapping:
    args:
      token: mcp-demo # 可以在 play-all-in-one.yaml 中找到的 token 秘钥名称。
      tools: # MCP 工具
        - name: echo-hello # MCP 工具名称
          desc: Echo a hello msg # MCP 工具描述
          schema: # MCP 工具参数,用有效的 JSON Schema 描述。
            type: object
            properties: {}
            required: []
    saveLog: false
    saveResult: false

事件的tools字段是一个数组,您可以通过一个函数实现多个tool。在调用函数时,Refunc 会添加两个内置参数:_call_type_call_method,其中 _call_method 是tool的名称。_call_type会表示调用来自MCP的什么类型,Tool、Resource或者Prompts。

阅读全文

安伯尼可RG40xxV掌机设置远程管理游戏

开启SSH

使用系统自带的文件管理器,编辑系统设置文件

/mnt/mod/ctrl/configs/system.cfg

添加开启ssh配置

global.ssh=1

然后重启,连接WIFI,从系统菜单配置获取IP地址。

进入一个游戏,然后暂停,不然系统自动锁屏休眠,网络会断,配置好FTP以后传游戏时候也这样操作。

安装VSFTP服务器

使用xshell或者其他ssh终端工具登录,密码同用户名(猜出来的),建议登录上去之后改掉,实测不影响系统使用。

ssh root@192.168.x.x

会发现周哥的系统就是原生的Ubuntu。

Welcome to Ubuntu 22.04 LTS (GNU/Linux 4.9.170 aarch64)

通过apt安装ftp服务器。

# 系统默认用的清华的源666
apt update
apt install vsftpd

配置VSFTP

直接在终端下vim配

mv /etc/vsftpd.conf /etc/vsftpd.conf.bak
vim /etc/vsftpd.conf

vsftp配置如下

listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
local_root=/mnt
allow_writeable_chroot=YES
pasv_enable=YES

开启root使用ftp登录

vim /etc/ftpusers
删除或注释掉root行

重启vsftp

systemctl restart vsftpd

通过FTP管理游戏文件

下载FileZilla,FTP连接游戏机IP即可,FTP客户端使用参考其他教程。

系统卡目录

/mmc

扩展卡目录

/sdcard
阅读全文

Docker部署MySQL主从复制

运维现场

已有一个通过Docker部署的MySQL单实例,实例中有多个库,且已有数据,备份容灾目的现扩充从库。

docker run -d --name mysql --restart unless-stopped -p 3406:3306 --log-opt max-size=50m \
-v /data/mysql:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=xxx \
mysql:5.7

主库调整

The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may !includedir additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d.

MySQL的镜像已经把主配置my.cnf映射到/etc/mysql/conf.d目录,所以只需自定义一个my.conf,通过目录挂载到容器里面即可。

[mysqld]
skip-host-cache
skip-name-resolve
server_id=1  //设置服务id
log_bin=mysql-bin //开启二进制日志
binlog-ignore-db=mysql
binlog_cache_size=1M
binlog_format=mixed
expire_logs_days=7
slave_skip_errors=1062

[mysql]

[mysqldump]
quick
quote-names
max_allowed_packet=16M

停止当前容器,修改启动命令,挂载my.cnf,重新启动。

docker run -d --name mysql --restart unless-stopped -p 3406:3306 --log-opt max-size=50m \
-v /data/mysql:/var/lib/mysql \
-v /data/mysql.conf.d:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=xxx \
mysql:5.7

查看master状态。

MySQL [(none)]> show master status;
+------------------+-----------+--------------+------------------+-------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+-----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 452181159 |              | mysql            |                   |
+------------------+-----------+--------------+------------------+-------------------+

从库搭建

配置slave的my.cnf,在另外一台机器上,启动一个空实例。

[mysqld]
skip-host-cache
skip-name-resolve
server_id=2
log_bin=slave-bin
binlog-ignore-db=mysql
binlog_cache_size=1M
binlog_format=mixed
expire_logs_days=7
slave_skip_errors=1062
relay_log=slave-relay-bin
log_slave_updates=1
read_only=1

[mysql]

[mysqldump]
quick
quote-names
max_allowed_packet=16M
docker run -d --name mysql --restart unless-stopped -p 3406:3306 --log-opt max-size=50m \
-v /data/mysql:/var/lib/mysql \
-v /data/mysql.conf.d:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=xxx \
mysql:5.7

全量备份主库

首先锁表。

#全备主库时需要另开一个终端,给数据库加上读锁,避免在备份期间有其他人在写入导致数据不一致
#此锁表的终端必须在备份完成以后才能退出
mysql> flush tables with read lock;

记录binlog状态,锁表之后binlog的Position就不会再变了,记录下File和Position。

MySQL [(none)]> show master status;
+------------------+-----------+--------------+------------------+-------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+-----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 461472295 |              | mysql            |                   |
+------------------+-----------+--------------+------------------+-------------------+

操作备份,备份完成,即可释放表锁。

mysqldump -h 172.x.x.10 -P 3406 -uroot -pxxx --all-databases > all-database-$(date '+%F-%H-%M-%S').sql

#解除主库的锁表状态,直接退出交互式界面即可
mysql> quit

把全量数据导入到从库中

mysql -h 172.x.x.11 -P 3406 -uroot -pxxx < all-database-2024-10-09-11-27-41.sql

配置从库同步

登录从库,执行change master,注意master_log_file和master_log_pos,填写在备份主库前记录值。

change master to master_host='172.x.x.10',master_port=3406,master_user='root',master_password='xxx',master_log_file='mysql-bin.000002',master_log_pos=461472295;

查看从库状态。

MySQL [(none)]> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.x.x.10
                  Master_User: root
                  Master_Port: 3406
                Connect_Retry: 30
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 479860795
               Relay_Log_File: slave-relay-bin.000003
                Relay_Log_Pos: 111190829
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 479860795
              Relay_Log_Space: 432038788
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID: cd0f01f3-27c4-11ef-9394-0242ac130002
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:

可以看到Slave_IO_Running和Slave_SQL_Running,开始为No,需要执行slave start。

mysql> slave start
mysql> show slave status \G;
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...

验证同步

通过主库创建库表,写入数据,验证从库同步。

阅读全文

StableDiffusion

Models

CheckPoint

WebUI

# ubuntu 22.04
sudo apt install libgl1 libglib2.0-0 libgoogle-perftools4 libtcmalloc-minimal4
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
# 切换到指定版本
git checkout -b v1-10-1 tags/v1.10.1
./webui.sh
# chinese interface
https://github.com/VinsonLaro/stable-diffusion-webui-chinese
阅读全文