0%

例如:删除/data/log/目录下所有10天前的.log文件

1
find /data/log/ -type f -name "*.log" -mtime +10 -exec rm -f {} \;

只查看要删除的文件有哪些,不真正删除文件

1
2
logfiles=$(find /data/log/ -type f -name "*.log" -mtime +10)
echo $logfiles
阅读全文 »

数据库相关概念

  • 数据库(DataBase) 存储数据仓库
  • 数据库管理系统(DateBase Management System)(DBMS) 操纵和管理数据库的大型软件
  • SQL(Structured Query Language)(SQL) 操作关系型数据库的编程语言,定义了一套操作关系数据库的统一标准

关系模型

关系模型本质上就是若干个存储数据的二维表

  • 表的每一行称为记录(Record),记录是一个逻辑意义上的数据。
  • 表的每一列称为字段(Column),同一个表的每一行记录都拥有相同的若干字段。
  • 字段定义了数据类型(整型、浮点型、字符串、日期等),以及是否允许为NULL
阅读全文 »

问题描述

在RHEL中运行了一个自定义的systemd服务,启动报错 Start operation timed out, 在后台执行systemctl start也被阻塞, 不能自动退出。

service配置文件如下:

1
2
3
4
5
6
7
8
9
[Unit]
After=network.target

[Service]
Type=forking
ExecStart=/path/to/monitor_network.sh

[Install]
WantedBy=multi-user.target

解决方法

查阅资料,发现Type=forking有问题,这里应该改成Type=simple。

阅读全文 »

先查看当前网卡

1
2
3
4
nmcli con show
NAME UUID TYPE DEVICE
eth0 XX ethernet eth0
lo XX loopback lo

例如,配置eth0网卡的static ip为10.206.216.93, gateway 10.206.216.254, DNS 10.204.16.18

1
2
3
nmcli con del eth0
nmcli con add con-name eth0 autoconnect yes type ethernet ifname eth0 ip4 10.206.216.93/24 gw4 10.206.216.254 ipv4.dns "8.8.8.8 4.4.4.4"
nmcli con up eth0

使用ip命令配置临时路由

添加静态路由

1
ip route add <目的网络> via <下一跳IP> dev <网卡接口名称>

例: 给eth0网卡添加一个到达 192.168.2.0/24 网络,下一跳为 192.168.1.254 的路由

1
ip route add 192.168.2.0/24 via 192.168.1.254 dev eth0

删除静态路由

1
ip route del <目的网络> via <下一跳IP> dev <网卡接口名称>

例: 删除上述的静态路由

1
ip route del 192.168.2.0/24 via 192.168.1.254 dev eth0

使用nmcli配置永久路由

添加静态路由
例: 给eth0网卡添加一个到达 192.168.2.0/24 网络,下一跳为 192.168.1.254 的路由

1
nmcli connection modify eth0 +ipv4.routes "192.168.2.0/24 192.168.1.254"

如果需要添加多个路由,可以用逗号分隔的方式添加:

1
nmcli connection modify eth0 +ipv4.routes "192.168.2.0/24 192.168.1.254,192.168.3.0/24 192.168.1.254"

删除静态路由

1
nmcli connection modify eth0 -ipv4.routes "192.168.2.0/24 192.168.1.254"
阅读全文 »

环境

VMware Rocky Linux 9.4 MySQL 8.0

安装mysqlclient报错

1
2
yum install python3-devel
pip3 install mysqlclient

报错:

1
2
3
4
5
6
7
8
9
Downloading http://mirrors.aliyun.com/pypi/packages/37/fb/d9a8f763c84f1e789c027af0ffc7dbf94c9a38db961484f253f0552cbb47/mysqlclient-2.2.1.tar.gz (89 kB)
|████████████████████████████████| 89 kB 80.1 MB/s
Installing build dependencies ... done
Getting requirements to build wheel ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 /usr/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmp5fvp1dau
cwd: /tmp/pip-install-1nnewfot/mysqlclient_93347d191d2942c8b2bb37681a22fd09
Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
阅读全文 »

安装并启动MySQL

1
2
dnf install -y mysql-server
systemctl start mysqld.service

设置MySQL的root用户密码

1
mysql_secure_installation

mysql_secure_installation是MySQL的一个安全脚本,执行后根据提示选择密码强度,输入root用户的密码

查看MySQL的版本

通过mysqladmin查到MySQL版本为8.0.36

1
2
3
4
5
mysqladmin -u root -p version
Enter password:

....
Server version 8.0.36

连接MySQL

1
mysql -u root -p

再输入你之前设置的root用户密码即可。

阅读全文 »

Django快速上手

参考: Django快速上手

再写几个页面

编辑demo1/urls.py, 添加URL和视图函数映射

1
2
3
4
5
urlpatterns = [
path('index/', views.index),
path('user/list/', views.user_list),
path('user/add/', views.user_add),
]

编辑app01/views.py,添加几个函数

1
2
3
4
5
6
7
8
9
10
11
from django.shortcuts import render, HttpResponse

# Create your views here.
def index(request):
return HttpResponse("Hello World")

def user_list(request):
return HttpResponse("User List")

def user_add(request):
return HttpResponse("User add")

templates模板的运用

阅读全文 »

问题描述

我想通过iptables允许以下这20个端口通过:

1
iptables -A INPUT -p tcp -i eth0 -m multiport --dports 22,80,443,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46 -j ACCEPT

执行后报错,iptables: too many ports specified

原因

查看iptables官方文档, 发现iptables单条multiports规则最多只支持15个端口。 原文如下:

阅读全文 »

问题描述

客户有一台基于Hyper-V创建的RHEL9虚拟机, 安装了MicroK8s, 启动正常。
虚拟机重启后, kubectl报错: Unable to connect to the server: x509: certificate has expired or is not yet valid

定位过程

这个报错说明MicroK8s apiserver证书的有效时间不对。 首先简单了解下Microk8s证书(以下内容 by ChatGPT)

阅读全文 »