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-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设置自定义变量。

2023-08-24
发表者 Venus
juniper配置dnat规则并配置安全策略已关闭评论

juniper配置dnat规则并配置安全策略

# 添加pool用于dnat时匹配要转发到的目的地址及端口
root@juniper1# set security nat destination pool kibana address 10.1.2.5 port 5601    
root@juniper1# set security nat destination pool es description "elasticsearch port" address 10.1.2.5 port 9200    

# 查看pool(用问号?提示时会显示出来所有的pool)
root@juniper1# show security nat destination pool kibana 
address 10.1.2.5/32 port 5601;

# 查看dnat规则集,ssh为规则集名
root@juniper1# show security nat destination rule-set ssh    

# 添加具体的规则到某个规则集,es为规则名
root@juniper1# set security nat destination rule-set ssh rule es description "elasticsearch" match destination-address 174.71.214.155     
root@juniper1# set security nat destination rule-set ssh rule es description "elasticsearch" match protocol tcp destination-port 9200    
root@juniper1# set security nat destination rule-set ssh rule es then destination-nat pool es    
root@juniper1# commit 


# 查看所有服务,也就是安全策略中的 services
root@juniper1# show applications 

# 通过问号可以显示所有的服务名
root@juniper1# show applications application ? 

# 通过指定服务名,可以查看此服务的协议端口信息
root@juniper1# show applications application es 

# 创建用户自定义应用服务,服务名叫es
root@juniper1# set applications application es protocol tcp destination-port 9200 description elasticsearch 

# 删除一条自定义服务
root@juniper1# delete applications application es    

# 查看安全策略
root@juniper1# show security policies from-zone untrust to-zone trust 

# 安全策略,往一个已有的策略中添加一个新服务,已有的策略名为 ping,服务名为 es
root@juniper1# set security policies from-zone untrust to-zone trust policy ping match application es

# 或者创建一个新策略
root@juniper1# set security policies from-zone untrust to-zone trust policy es then permit 
root@juniper1# set security policies from-zone untrust to-zone trust policy es match application es

root@juniper1# commit