Rootop 服务器运维与web架构

2022-10-19
发表者 Venus
nginx绑定大量域名时需要修改的两个参数已关闭评论

nginx绑定大量域名时需要修改的两个参数

nginx在添加量大虚拟主机时重启nginx报错。

nginx: [warn] could not build optimal server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 64; ignoring server_names_hash_bucket_size
http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    # 添加或修改下面2行
    server_names_hash_max_size 4096;
    server_names_hash_bucket_size 1024;

    include vhost/*.conf;
}

2022-10-18
发表者 Venus
通过单个配置文件实现腾讯云双网卡配置多ip已关闭评论

通过单个配置文件实现腾讯云双网卡配置多ip

之前都是用子配置文件方式,比如 ifcfg-eth0:0 ifcfg-eth0:1这种,需要创建多个配置文件。
现在通过单个配置文件实现多ip配置。

# 第一块网卡

[root@VM-0-3-centos network-scripts]# cat ifcfg-eth0
BOOTPROTO=static
DEVICE=eth0
HWADDR=52:54:00:4f:c4:e4
ONBOOT=yes
PERSISTENT_DHCLIENT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=172.17.0.3
NETMASK=255.255.240.0
GATEWAY=172.17.0.1

IPADDR1=172.17.0.13
NETMASK1=255.255.240.0

IPADDR2=172.17.0.14
NETMASK2=255.255.240.0

IPADDR3=172.17.0.15
NETMASK3=255.255.240.0

IPADDR4=172.17.0.2
NETMASK4=255.255.240.0

IPADDR5=172.17.0.8
NETMASK5=255.255.240.0

# 第二块网卡配置

[root@VM-0-3-centos network-scripts]# cat ifcfg-eth1
BOOTPROTO=static
DEVICE=eth1
ONBOOT=yes
PERSISTENT_DHCLIENT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=172.17.0.6
NETMASK=255.255.240.0

IPADDR1=172.17.0.11
NETMASK1=255.255.240.0

IPADDR2=172.17.0.12
NETMASK2=255.255.240.0

IPADDR3=172.17.0.16
NETMASK3=255.255.240.0

IPADDR4=172.17.0.4
NETMASK4=255.255.240.0

IPADDR5=172.17.0.5
NETMASK5=255.255.240.0

# 配置策略路由

echo "10 t1" >> /etc/iproute2/rt_tables
echo "20 t2" >> /etc/iproute2/rt_tables
ip route add default dev eth0 via 172.17.0.1 table 10
ip route add default dev eth1 via 172.17.0.1 table 20
ip rule add from 172.17.0.13 table 10
ip rule add from 172.17.0.14 table 10
ip rule add from 172.17.0.15 table 10
ip rule add from 172.17.0.2 table 10
ip rule add from 172.17.0.3 table 10
ip rule add from 172.17.0.8 table 10

ip rule add from 172.17.0.11 table 20
ip rule add from 172.17.0.12 table 20
ip rule add from 172.17.0.16 table 20
ip rule add from 172.17.0.4 table 20
ip rule add from 172.17.0.5 table 20
ip rule add from 172.17.0.6 table 20

# 测试ip连通性

#!/bin/bash
ip a | grep -o -e 'inet [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'|grep -v "127.0.0"|awk '{print $2}' > ip

while read line || [[ -n ${line} ]]
do
        line=`curl -s --interface $line -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.62" https://ipv4.icanhazip.com/`
        echo "ip地址 " $line
done < ip

2022-10-09
发表者 Venus
vmdk转阿里云raw已关闭评论

vmdk转阿里云raw

本地vmware虚拟机的vmdk转成阿里云的raw格式镜像

根据官方文档:https://help.aliyun.com/document_detail/57187.html

D:\>qemu-img convert -f vmdk -O raw 1.vmdk 2.raw
qemu-img: error while writing at byte 0: Input/output error

报如上的错误,发工单以后可以通过下面参数转换

qemu-img.exe convert 1.vmdk -O vpc -o subformat=dynamic 2.raw

在等待工单回复过程中找到如下参数转换完成,同样可以导入到镜像。

D:\>qemu-img convert 1.vmdk -f vmdk -O qcow2 2.qcow2

2022-08-23
发表者 Venus
xargs占位符已关闭评论

xargs占位符

比如在log目录下有3个文件,文件名为a、b、c,现在需要改名,加上.bak。

[root@iZj6c5o8z3bqyepm9pw4xsZ log]# ll
总用量 0
-rw-r--r-- 1 root root 0 8月  23 09:46 a
-rw-r--r-- 1 root root 0 8月  23 09:46 b
-rw-r--r-- 1 root root 0 8月  23 09:46 c

通过-I参数指定一个占位符

[root@iZj6c5o8z3bqyepm9pw4xsZ log]# ls | xargs -I filename sh -c "mv filename filename.bak" 
[root@iZj6c5o8z3bqyepm9pw4xsZ log]# ll
总用量 0
-rw-r--r-- 1 root root 0 8月  23 09:46 a.bak
-rw-r--r-- 1 root root 0 8月  23 09:46 b.bak
-rw-r--r-- 1 root root 0 8月  23 09:46 c.bak

2022-08-10
发表者 Venus
系统日志时间和实际时间相差12小时已关闭评论

系统日志时间和实际时间相差12小时

# 问题:2个日志里的时间都是和实际差12小时
/var/log/messages
/var/log/secure

# 系统时区已经设置过

[root@instance-20220524-1844 ~]# date
2022年 08月 09日 星期二 22:26:56 CST

# 从当前系统时间设置硬件时钟

[root@instance-20220524-1844 ~]# hwclock -w

发现还是错误

最后通过重启日志服务解决

[root@instance-20220524-1844 ~]# systemctl restart rsyslog