X7ROOT File Manager
Current Path:
/var/VMOptimizationToolsLinux
var
/
VMOptimizationToolsLinux
/
📁
..
📄
LinuxUpdate.XML
(645 B)
📄
SangforVMSTool
(3.11 KB)
📄
SangforVMSTool.service
(194 B)
📄
action_common.sh
(13.34 KB)
📄
busybox_cmd_ln.sh
(2.24 KB)
📄
collect_test_data.sh
(1.16 KB)
📄
common_config.sh
(278 B)
📄
data_test_tool.sh
(12.59 KB)
📄
debian_vmconfig.sh
(10.74 KB)
📄
guest_system_config.sh
(1.82 KB)
📄
log.sh
(1.36 KB)
📄
mod_test.sh
(3.69 KB)
📄
mod_test1.sh
(914 B)
📄
net_common.sh
(915 B)
📄
redhat_vmconfig.sh
(11.14 KB)
📄
sangfor_guest_datareport
(21.66 KB)
📄
sangfor_heartalive.sh
(2.37 KB)
📄
sangfor_module_update
(28.11 KB)
📄
sangfor_set_network.sh
(504 B)
📄
sangfor_sfping
(3.85 KB)
📄
sangfor_sshkey_gen
(1.29 KB)
📄
sangfor_update_ipc_callback
(5.29 KB)
📄
sangfor_vm_proxyd
(3.45 KB)
📄
sangfor_vm_proxyd_r
(4.4 KB)
📄
sangfor_vm_proxyd_w
(1.32 KB)
📄
sangfor_vmconfig
(2.4 KB)
📄
sangfor_vmconfig_common
(27.99 KB)
📄
sangfor_vmconfig_ipc_callback
(4.75 KB)
📄
sangfor_watchdog
(3.95 KB)
📄
sfping.c
(15.68 KB)
📄
sfping.pl
(6.15 KB)
📄
startall
(1.78 KB)
📄
stopall
(1.11 KB)
📄
suse_vmconfig.sh
(6.19 KB)
📁
tools_x64
📁
tools_x86
📄
uni_test.sh
(2.59 KB)
📄
update_common_func
(4.35 KB)
📄
update_common_header
(4.86 KB)
📄
update_config
(2.89 KB)
📄
update_install
(28.84 KB)
📄
virtio_nic_attr_set.sh
(2.42 KB)
📄
virtio_nic_compat.sh
(5.28 KB)
📄
vm_ip_recover.sh
(16.66 KB)
📄
vm_ipc.sh
(9.06 KB)
📄
vmconfig_common_func
(10.76 KB)
📄
vmconfig_common_header
(3.37 KB)
📄
vmconfig_config
(805 B)
📄
vmtools-install.sh
(31.16 KB)
📄
watch_test.sh
(313 B)
📄
watchdog.sh
(1.39 KB)
📁
x64
📁
x86
Editing: redhat_vmconfig.sh
#!/bin/bash shell_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) . "${shell_dir}/vmconfig_common_func" # delete all config file of interface # param $1: ifname,eg. eth0 # return: none redhat_delete_orig_cfg_file() { local ifname=$1 test -z "${g_redhat_network_cfg_dir}" && return if [ x"$g_redhat_network_cfg_dir" == x"" ];then log_error "##redhat network cfg dir is invalid" return fi for file in ${g_redhat_network_cfg_dir}/ifcfg-* do device=`cat $file | grep "^\s*DEVICE" |awk -F= '{print $2}'` device=`echo $device` if [ x"$ifname" == x"$device" ];then log_info "rm file $file,device=${device}" rm -f "$file" 2>/dev/null if [ $? -ne 0 ];then log_warn "remove file $file...failed" fi fi done } # get the current config file of interface # param $1: ifname,eg. eth0 # output: config file name # return 0(success),1(fail) redhat_get_config_file() { local ifname=$1 local ipaddr="" local netmask="" local first_file="" test -z "$ifname" && return 1 ipaddr=`get_if_ip $ifname` netmask=`get_if_mask "$ifname"` for file in ${g_redhat_network_cfg_dir}/ifcfg-* do device=`get_value_from_config "$file" "DEVICE"` if [ x"$ifname" != x"$device" ];then continue fi if test -z "$first_file";then first_file="$file" fi test -z "$netmask" && break test -z "$ipaddr" && break prefix=`mask2cdr "${netmask}"` cfg_ip=`get_value_from_config "$file" "IPADDR"` cfg_mask=`get_value_from_config "$file" "NETMASK"` cfg_prefix=`get_value_from_config "$file" "PREFIX"` if [ x"${cfg_ip}" != x"${ipaddr}" ];then continue fi if [ x"${cfg_mask}" != x"${netmask}" ] && [ x"${cfg_prefix}" != x"${prefix}" ];then continue fi echo $file return 0 done echo "$first_file" return 1 } # redhat series system generate network config # param $1: ifname,eg:eth0 # param $2: protocol,eg:dhcp|static # param $3: ip,eg:192.168.100.100 # param $4: net mask,eg:255.255.255.0 # param $5: gateway,eg:192.168.100.1 # param $6: primary dns,eg:192.168.100.1 # param $7: secondary dns,eg:8.8.8.8 # param $8: mac address,eg:FE:FC:FE:66:82:32 # return 0(success),1(fail) redhat_gen_network_cfg_file() { local ifname=$1 local protocol=$2 local ipaddr=$3 local netmask=$4 local gateway=$5 local dns1=$6 local dns2=$7 local macaddr=$8 test -z "$ifname" && return 1 if [ x"$protocol" != x"$PROTO_STATIC" ] && [ x"$protocol" != x"$PROTO_DHCP" ];then log_error "error,invalid proto $protocol" return 1 fi #Fix TD 87612, centos6.5设置配置时候需要设置网卡的MAC地址,因为centos6.5的NetworkManager服务是根据MAC地址设置指定网卡。没有设置的话,可能其他网卡也会用。 is_valid_mac_address "$macaddr" if [ $? -ne 0 ];then log_error "[redhat_gen_network_cfg_file]error,macaddr is not valid for ${ifname} : ${macaddr}" return 1 fi log_info "config:{$ifname,$protocol,$ipaddr,$netmask,$gateway,$dns1,$dns2}" redhat_delete_orig_cfg_file $ifname cfg_file="$g_redhat_network_cfg_dir/ifcfg-$ifname" echo "TYPE=Ethernet" > $cfg_file echo "DEVICE=$ifname" >> $cfg_file echo "BOOTPROTO=$protocol" >> $cfg_file # macaddr 上面校验了有效性,这里不需要检查了 echo "HWADDR=$macaddr" >> $cfg_file is_valid_inet_address $ipaddr if [ $? -eq 0 ];then echo "IPADDR=$ipaddr" >> $cfg_file fi is_valid_inet_address $netmask if [ $? -eq 0 ];then echo "NETMASK=$netmask" >> $cfg_file fi is_valid_inet_address $gateway if [ $? -eq 0 ];then echo "GATEWAY=$gateway" >> $cfg_file fi metric=`cat /proc/net/dev |sed -n "/$ifname:/="` if ! test -z $metric;then echo "METRIC=10$metric" >> $cfg_file fi is_valid_inet_address $dns1 if [ $? -eq 0 ];then echo "DNS1=$dns1" >> $cfg_file fi is_valid_inet_address $dns2 if [ $? -eq 0 ];then echo "DNS2=$dns2" >> $cfg_file fi echo "ONBOOT=yes" >> $cfg_file echo "NAME=$ifname" >> $cfg_file return 0 } redhat_network_cfg_handle() { local ifname=$1 local ipaddr=$2 local netmask=$3 local gateway=$4 local dns1=$5 local dns2=$6 local macaddr=$7 local protocol=$PROTO_STATIC if test -z $ifname;then log_error "ifname is needed" return 1 fi if test -z $macaddr;then log_error "[redhat_network_cfg_handle]macaddr is needed for ${ifname}" return 1 fi # 如果没有配置ip,获取接口当前的配置 if test -z "$ipaddr";then method=`nmcli_get_config_ip_method $ifname` if ! test -z "$method";then if [ x"$method" == x"manual" ];then ipaddr=`nmcli_get_config_ip $ifname` netmask=`nmcli_get_config_mask $ifname` gateway=`nmcli_get_config_gateway $ifname` else protocol=$PROTO_DHCP fi log_info "[nmcli]origin proto:$protocol,ip:$ipaddr,netmask:$netmask,gateway:$gateway" else cur_config_file=`redhat_get_config_file "$ifname"` if test -z "$cur_config_file";then log_warn "ifname:$ifname config file is not exist" protocol=$PROTO_DHCP else log_debug "ifname:$ifname config file is $cur_config_file" protocol=`get_value_from_config "$cur_config_file" "BOOTPROTO"` if test -z "$protocol";then protocol=$PROTO_STATIC fi ipaddr=`get_value_from_config "$cur_config_file" "IPADDR"` netmask=`get_value_from_config "$cur_config_file" "NETMASK"` if test -z "$netmask";then prefix=`get_value_from_config "$file" "PREFIX"` if ! test -z "$prefix";then netmask=`cdr2mask ${prefix}` fi fi gateway=`get_value_from_config "$cur_config_file" "GATEWAY"` log_info "[config]origin proto:$protocol,ip:$ipaddr,netmask:$netmask,gateway:$gateway" fi fi fi # 配置中可能获取不到ip,通过命令获取 if [ x"$PROTO_STATIC" == x"$protocol" ];then if test -z "$ipaddr" || test -z "$netmask";then log_warn "$ifname get config from cmd" ipaddr=`get_if_ip $ifname` netmask=`get_if_mask $ifname` if test -z "$ipaddr" || test -z "$netmask";then log_warn "$ifname get ip info failed,use default proto (dhcp)" protocol=$PROTO_DHCP else protocol=$PROTO_STATIC fi gateway=`get_if_gateway $ifname` log_info "[cmd]origin proto:$protocol,ip:$ipaddr,netmask:$netmask,gateway:$gateway" fi fi redhat_gen_network_cfg_file "$ifname" "$protocol" "$ipaddr" "$netmask" "$gateway" "$dns1" "$dns2" "${macaddr}" ip a flush dev "$ifname" >/dev/null 2>&1 return 0 } redhat_active_dns_cfg() { local cfg_file=$1 #iface cfg file local new_dns=$2 # x.x.x.x ip local dns_area=$3 # DNS1 or DNS2 cfg_dns=$(grep -w "$dns_area" $cfg_file) if [ "$cfg_dns" != "" ]; then old_dns=`get_value_from_config "$file" "$dns_area"` # 新旧dns一样,不处理 if [ "$old_dns" == "$new_dns" ]; then log_info "$old_dns the same with $new_dns, return" return 0 fi # ifcfg-ethx删除指定DNS log_info "del line : $dns_area=$old_dns in cfg file $cfg_file" sed -i "/$dns_area=$old_dns/d" $cfg_file || sed -i "/$dns_area=$old_dns/d" $cfg_file || log_error "delete line failed!!!" # 确认该DNS是不是在别的cfg文件也配置,没有可以从resolv文件删除 dns_tmp=$(grep -w "$old_dns" ${g_redhat_network_cfg_dir}/ifcfg-*) if [ "$dns_tmp" == "" ]; then log_info "del line : nameserver $old_dns in file $g_dns_config_file" sed -i "/nameserver $old_dns/d" $g_dns_config_file || sed -i "/nameserver $old_dns/d" $g_dns_config_file || log_error "delete line failed!!!" fi fi if [ "$new_dns" != "" ]; then # 没有直接添加一行 DNSx=x.x.x.x log_info "append new $dns_area=$new_dns to file $cfg_file" echo "$dns_area=$new_dns" >> $cfg_file || log_error "append new dns $dns_area=$new_dns failed!!!" cfg_dns=$(grep -w "$new_dns" $g_dns_config_file) if [ "$cfg_dns" == "" ]; then log_info "append new dns nameserver $new_dns to file $g_dns_config_file" echo "nameserver $new_dns" >> $g_dns_config_file || log_error "append faied" fi else log_info "$dns_area is empty" fi } # acmp端提出的需求为仅修改dns的下直接覆盖系统原有的所有DNS,故这里直接生成一个新的dns文件,随后直接覆盖原有的dns文件 # $1 dns1 # $2 dns2 redhat_overwrite_dns() { dns1=$1 dns2=$2 tmp_file="${g_dns_config_file}_sangfor_tmp" log_info "create new dns tmp file ${tmp_file}" if [ "$dns1" != "" ]; then # PS:或运算遵循最短运算规则,当第一个条件为真就直接返回,后面的就不执行了,故前面的指令运行失败了才会执行后续指令 echo "nameserver $dns1" >> $tmp_file || echo "nameserver $dns1" >> $tmp_file || log_error "append $dns1 faied" fi if [ "$dns2" != "" ]; then echo "nameserver $dns2" >> $tmp_file || echo "nameserver $dns2" >> $tmp_file || log_error "append $dns2 faied" fi log_info "rename file $tmp_file to $g_dns_config_file" mv -f $tmp_file $g_dns_config_file || mv -f $tmp_file $g_dns_config_file || log_error "rename failed!!" } #redhat_dns_cfg_handle "$ifaces" "$dns1" "$dns2" #仅更新指定网口的DNS并且不重启服务立即生效 redhat_dns_cfg_handle() { local ifaces=$1 local dns1=$2 local dns2=$3 for iface in $ifaces do log_info "update dns for iface $iface with dns1: $dns1, dns2: $dns2" iface_match=0 for file in ${g_redhat_network_cfg_dir}/ifcfg-* do device=`get_value_from_config "$file" "DEVICE"` if [ x"$iface" != x"$device" ];then continue fi iface_match=1 log_info "device name match in file $file" cfg_ip=`get_value_from_config "$file" "IPADDR"` test -z "$cfg_ip" && log_info "$iface invalue ipaddr" && break protocol=`get_value_from_config "$file" "BOOTPROTO"` if [ "$protocol" != "$PROTO_STATIC" ]; then log_info "iface $iface proto is $protocol, not static, skip" break fi redhat_active_dns_cfg $file "$dns1" "DNS1" redhat_active_dns_cfg $file "$dns2" "DNS2" done if [ $iface_match -eq 0 ]; then log_info "iface $iface not match any file in ${g_redhat_network_cfg_dir}" fi done redhat_overwrite_dns "$dns1" "$dns2" sync }
Upload File
Create Folder