Rootop 服务器运维与web架构

2023-09-14
发表者 Venus
安装mysql8.0.33报错已关闭评论

安装mysql8.0.33报错

系统版本:almalinux9.2

[root@db1 ~]# cat /etc/redhat-release 
AlmaLinux release 9.2 (Turquoise Kodkod)
[root@db1 ~]# uname -r
5.14.0-284.25.1.el9_2.x86_64

目的:安装mysql8.0.33二进制版本

在拷贝启动脚本时报了一个错误提示,如下:

cp: cannot create regular file '/etc/init.d/mysql': No such file or directory

在这个版本的系统中默认不安装chkconfig包用不了service命令,所以此路径不存在,需要手动安装下。

[root@db1 install-mysql8_0_33]# yum install -y chkconfig

# 在执行mysql命令进入控制台时,又报了个错

mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

# 查看mysql命令依赖的库

[root@db1 install-mysql8_0_33]# ldd /usr/local/mysql/bin/mysql |grep libtinfo
	libtinfo.so.5 => not found

# 查找系统中libtinfo开头的库文件

[root@db1 install-mysql8_0_33]# find / -name "libtinfo.so*"
/usr/lib64/libtinfo.so.6.2
/usr/lib64/libtinfo.so.6

# 做个软连接,把依赖的5版本链接到6版本上

[root@db1 install-mysql8_0_33]# ln -s /usr/lib64/libtinfo.so.6.2 /usr/lib64/libtinfo.so.5

再次执行mysql命令没有报错了。

# 查看这个库文件是哪个包提供的额

[root@db2 ~]# rpm -qf /usr/lib64/libtinfo.so.6
ncurses-libs-6.2-8.20210508.el9.x86_64

关于linux下的动态链接库资料参考:https://www.zhihu.com/tardis/bd/art/235551437

2023-09-14
发表者 Venus
NetworkManager网卡网络配置已关闭评论

NetworkManager网卡网络配置

系统版本为:almalinux9.2
通过nmcli命令配置网络信息,此命令由 NetworkManager 包提供。

# 查看当前配置文件,从RHEL9.0开始,以key-file格式保存在下面路径中
[root@localhost ~]# cat /etc/NetworkManager/system-connections/ens192.nmconnection 
[connection]
id=ens192
uuid=c887eead-1da4-31f7-9f28-3277c4a72774
type=ethernet
autoconnect-priority=-999
interface-name=ens192
timestamp=1694517980

[ethernet]

[ipv4]
method=auto

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]

通过method=auto判断现在是自动获取的状态。改为固定ip。

# 配置网卡ip,ens192为网卡名
[root@localhost ~]# nmcli connection modify ens192 ipv4.method manual ipv4.addresses 192.168.12.240/24 ipv4.gateway 192.168.12.1 ipv4.dns 114.114.114.114,8.8.8.8 connection.autoconnect yes 
[root@localhost ~]# cat /etc/NetworkManager/system-connections/ens192.nmconnection 
[connection]
id=ens192
uuid=c887eead-1da4-31f7-9f28-3277c4a72774
type=ethernet
autoconnect-priority=-999
interface-name=ens192
timestamp=1694662356

[ethernet]

[ipv4]
address1=192.168.12.240/24,192.168.12.1
dns=114.114.114.114;8.8.8.8;
method=manual

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]

 

# 添加额外的ip,单网卡多ip。
[root@localhost ~]# nmcli connection modify ens192  +ipv4.addresses 192.168.89.11/24
[root@localhost ~]# nmcli connection modify ens192  +ipv4.addresses 192.168.89.12/24
[root@localhost ~]# nmcli connection modify ens192  +ipv4.addresses 192.168.89.13/24
[root@localhost ~]# cat /etc/NetworkManager/system-connections/ens192.nmconnection 
[connection]
id=ens192
uuid=c887eead-1da4-31f7-9f28-3277c4a72774
type=ethernet
autoconnect-priority=-999
interface-name=ens192
timestamp=1694662356

[ethernet]

[ipv4]
address1=192.168.12.240/24,192.168.12.1
address2=192.168.89.11/24
address3=192.168.89.12/24
address4=192.168.89.13/24
dns=114.114.114.114;8.8.8.8;
method=manual

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]

 

# 激活配置
[root@localhost ~]# nmcli connection up ens192 

 

# 删除一个ip
[root@localhost ~]# nmcli connection modify ens192 -ipv4.addresses 192.168.89.13/24
[root@localhost ~]# cat /etc/NetworkManager/system-connections/ens192.nmconnection 
[connection]
id=ens192
uuid=c887eead-1da4-31f7-9f28-3277c4a72774
type=ethernet
autoconnect-priority=-999
interface-name=ens192
timestamp=1694669933

[ethernet]

[ipv4]
address1=192.168.12.240/24,192.168.12.1
address2=192.168.89.11/24
address3=192.168.89.12/24
dns=114.114.114.114;8.8.8.8;
method=manual

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]
# 另外仍然支持ifcfg-配置文件形式(但不建议)
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens192 
TYPE=Ethernet
Device=ens192
IPADDR=192.168.12.240
NETMASK=255.255.255.0
GATEWAY=192.168.12.1
DNS1=114.114.114.114
ONBOOT=yes
BOOTPROTO=static

# 通过systemctl重启无效
[root@localhost ~]# systemctl restart NetworkManager

# 需要下面方式重启
[root@localhost ~]# nmcli connection reload
[root@localhost ~]# nmcli networking off
[root@localhost ~]# nmcli networking on 

2023-09-06
发表者 Venus
html和php的url美化处理已关闭评论

html和php的url美化处理

# 访问地址
http://voice/launchGame/23?playerId=123&playMode=real_play&currency=USD&operatorCode=Cordish&jurisdiction=PA&skin=Instance001&loginToken=token123&language=bg&contestRef=321

当浏览器访问时,会提示404错误,因为网站根目录下不存在launchGame目录及23文件
实际这是前段美化url后的访问地址,需要在nginx中将其重定向到 index.html 中,js会获取参数进行处理。
nginx中重定向有2种指令配置
1、rewrite
2、try_files

这里采用try_files

location / 
{
	index index.php index.html;
	try_files $uri $uri/ /index.html;
}

这样html中的js代码会将 /launchGame/23?playerId=123&playMode=real_play&currency=USD&operatorCode=Cordish&jurisdiction=PA&skin=Instance001&loginToken=token123&language=bg&contestRef=321
每一部分进行处理。

php的url美化处理
# 访问地址
http://voice/?user=1&pass=2
可以看到并没有具体到某个资源文件,例如index.php
但是配置文件中index指令指定了默认页为 index.php 所以url中的参数在index.php中是可以$_GET获取的

如果想通过try_files交给别的文件处理,则需要下面的配置

server
{
	listen        80;
	server_name  voice;
	root   "D:/phpstudy_pro/WWW/pt";
	index index.php index.html;
	
	try_files $uri $uri/ /a.php$is_args$args;

	location ~ \.php(.*)$
	{
		fastcgi_pass   127.0.0.1:9001;
		fastcgi_index  index.php;
		fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
		fastcgi_param  PATH_INFO  $fastcgi_path_info;
		fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
		include        fastcgi_params;
	}
}

http://voice/?user=1&pass=2 通过此链接来分析

# 情况1
$uri = /
匹配不到任何文件,找默认页 index.php或者index.html(取决于前后顺序,如果index.php文件不存在,则找index.html)。

# 情况2
$uri/,由于$uri = / 所以$uri/ = //
如果没有index.php或者index.html文件,则会匹配到网站根目录,会将网站根目录文件列出来,但是没加 autoindex on; 参数的话会继续访问 /a.php 且响应403状态码 但是不会传递参数。
如果加上了 autoindex on; 配置,则列出来网站目录列表,不会继续访问下一个匹配(/a.php)。

# 情况3
去掉 $uri/ 配置部分,也就是配置为 try_files $uri /a.php$is_args$args;
如果没有index.php或者index.html文件,会继续匹配/a.php$is_args$args,此时会访问到a.php并且参数也传递过去。

2023-09-06
发表者 Venus
使用wireguard异地打通内网实现资源访问已关闭评论

使用wireguard异地打通内网实现资源访问

异地办公室有几台机器,安装了虚拟化用于测试环境,要实现在公司内部直接访问虚拟化资源就需要打通内网。
对防火墙设备不熟,这里通过软件方式实现。

在异地办公室虚拟化中创建一台虚拟机,安装wireguard,本地一台centos作为客户端连接对端。

异地网络信息:10.1.2.0/24 网段用于虚拟机,10.0.3.0/24 网段用于服务器的idrac管理口。

要求本地网络可以直接访问以上2个网段。

# 本地centos(ip 192.168.12.244)作为wg客户端连接异地wg服务器,配置文件如下

[root@lan-web ~]# cat us.conf 
[Interface]
PrivateKey = 私钥
Address = 10.100.0.2/32
DNS = 8.8.8.8,114.114.114.114

[Peer]
PublicKey = 公钥
Endpoint = 174.71.x.x:51820
AllowedIPs = 10.1.2.0/24, 10.0.3.0/24 # 只允许指定网段走wg
PersistentKeepalive = 25

# 启动wg

[root@lan-web ~]# wg-quick up ./us.conf 

# 关闭wg

[root@lan-web ~]# wg-quick down ./us.conf 

# 启动后可以看到添加了2条路由

[root@lan-web ~]# ip route show
default via 192.168.12.1 dev ens192 proto static metric 100 
10.0.3.0/24 dev us scope link 
10.1.2.0/24 dev us scope link 
192.168.12.0/24 dev ens192 proto kernel scope link src 192.168.12.244 metric 100 

此时在centos中已经可以ping通2个网段。
下面实现将内网指定的主机向2个网段的请求走wg。

# linux同时作为网关,配置snat,将指定源ip的请求走wg

[root@lan-web ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
[root@lan-web ~]# sysctl -p
[root@lan-web ~]# iptables -F
[root@lan-web ~]# iptables -t nat -F
[root@lan-web ~]# iptables -t nat -A POSTROUTING -s 192.168.12.23/32 -j SNAT --to-source 10.100.0.2
[root@lan-web ~]# iptables -t nat -A POSTROUTING -s 192.168.12.201/32 -j SNAT --to-source 10.100.0.2

# 三层交换添加静态路由

[HUAWEI]ip route-static 10.1.2.0 24 192.168.12.244 
[HUAWEI]ip route-static 10.0.3.0 24 192.168.12.244 

完成。

2023-08-24
发表者 Venus
关于nignx中正则括号捕获组已关闭评论

关于nignx中正则括号捕获组

server
{
    listen       80 default_server;
    server_name  ~^(\w+\.)?(test\.com)$;

    root /www/$1$2;
    set $san $1;
    set $er  $2;


    location ~* \.(jpeg|png|gif|jpg)$
	#location /
    {
		types {}
		default_type text/html;
		echo $san "</br>";
		echo $er  "</br>";
		echo $1   "</br>";
		echo $2   "</br>";
		echo $uri;
    }
    
}


# 当访问 http://img.test.com/1.txt 时,返回404错误,日志中报错:
 open() "/www/img.test.com/1.txt" failed (2: No such file or directory)
 说明正则匹配的值为img.test.com($1=img. $2=test.com)去/www/目录下寻找此目录
 
# 当访问 http://img.test.com/1.jpeg 时,页面返回内容:
img.
test.com
jpeg

/1.jpeg
可以发现$2为空,猜测可能是因为出现第二个正则匹配并捕获内容导致$2变为未定义变量(并不知道真实原因是什么,只是猜测)。
因为第一个捕获组定义了,但是没有定义第二个捕获组。

当注释掉location ~* \.(jpeg|png|gif|jpg)$ 开启 #location / 时,则echo的内容全部返回。
如果想用之前的变量可以通过set设置自定义变量。