首页 > 其他分享 >web DevOps / qemu / kvm nat / kvm network / danei network

web DevOps / qemu / kvm nat / kvm network / danei network

时间:2023-09-12 16:35:34浏览次数:43  
标签:web sudo network kvm vm dev virsh null root

s

[root@euler share]# rpm -qa | grep openssh              # 查看ssh 
openssh-8.8p1-21.oe2203sp2.x86_64
openssh-server-8.8p1-21.oe2203sp2.x86_64
openssh-clients-8.8p1-21.oe2203sp2.x86_64
openssh-askpass-8.8p1-21.oe2203sp2.x86_64
[root@euler share]# pgrep -l sshd                       # 检索正在运行的进程
1625 sshd
[root@euler share]# ps -elf | grep sshd                 # 查看ssh进程
4 S root        1625       1  0  80   0 -  3473 do_sel 08:24 ?        00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
0 S root       43407   28302  0  80   0 -  5494 pipe_r 16:23 pts/7    00:00:00 grep --color=auto sshd

-  

[root@euler bin]# ll /usr/local/bin/           # 查看euler默认环境配置
总用量 30760
-rwxr-xr-x. 1 root root    64984  6月 29 01:23 blur_image
-rwxr-xr-x  1 root root  2322376  3月 18  2021 crashpad_handler
-rwxr-xr-x  1 root root 29108416  3月 18  2021 qq

-

[root@lindows ~]# /usr/local/bin/vm            # 定制化环境命令
vm {clone|remove|setip|completion} vm_name
[root@lindows ~]# more /usr/local/bin/vm       # 定制化脚本变量vm
#!/bin/bash
export LANG=C
. /etc/init.d/functions
CONF_DIR=/etc/libvirt/qemu
IMG_DIR=/var/lib/libvirt/images

function clone_vm(){
    local clone_IMG=${IMG_DIR}/${1};shift
    local clone_XML=${IMG_DIR}/${1};shift
    while ((${#} > 0));do
      if  [ -e ${IMG_DIR}/${1}.img ];then
          echo_warning
          echo "vm ${1}.img is exists"
          return 1
      else
          sudo -u qemu qemu-img create -b ${clone_IMG} -F qcow2 -f qcow2 ${IMG_DIR}/${1}.img 20G >/dev/null
          sed -e "s,node_base,${1}," ${clone_XML} |sudo tee ${CONF_DIR}/${1}.xml >/dev/null
          sudo virsh define ${CONF_DIR}/${1}.xml &>/dev/null
          msg=$(sudo virsh start ${1})
          echo_success
          echo ${msg}
      fi
      shift
    done
}
function remove_vm(){
    if $(sudo virsh list --all --name|grep -Pq "^${1}$");then
       img=$(sudo virsh domblklist $1 2>/dev/null |grep -Po "/var/lib/libvirt/images/.*")
       sudo virsh destroy  $1 &>/dev/null
       sudo virsh undefine $1 &>/dev/null
       sudo rm -f ${img}
       echo_success
       echo "vm ${1} delete"
    fi
}
function vm_setIP(){
    EXEC="sudo virsh qemu-agent-command $1"
    until $(${EXEC} '{"execute":"guest-ping"}' &>/dev/null);do sleep 1;done
    file_id=$(${EXEC} '{"execute":"guest-file-open",
              "arguments":{"path":"/etc/sysconfig/network-scripts/ifcfg-eth0","mode":"w"}}' |\
               python3 -c 'import json;print(json.loads(input())["return"])')
    body=$"# Generated by dracut initrd\nDEVICE=\"eth0\"\nONBOOT=\"yes\"\nNM_CONTROLLED=\"yes\"\nTYPE=\"Ethernet\"\nBOOTPROTO=\"static\"\nIPADDR=\"${2}\"\nPREFIX=24\nGATEWAY=\"${2%.*}.254\"\nDNS1=\"${2%.*}.254\""
    base64_body=$(echo -e "${body}"|base64 -w 0)
    ${EXEC} "{\"execute\":\"guest-file-write\",
              \"arguments\":{\"handle\":${file_id},\"buf-b64\":\"${base64_body}\"}}" &>/dev/null
    ${EXEC} "{\"execute\":\"guest-file-close\",\"arguments\":{\"handle\":${file_id}}}" &>/dev/null
    sudo virsh reboot ${1} &>/dev/null
}
function vm_completion(){
    cat <<"EOF"
__start_vm()
{
  COMPREPLY=()
  local cur
  cur="${COMP_WORDS[COMP_CWORD]}"

  if [[ "${COMP_WORDS[0]}" == "vm" ]] && [[ ${#COMP_WORDS[@]} -eq 2 ]];then
     COMPREPLY=($(compgen -W "clone remove setip" ${cur}))
  fi
  if [[ "${COMP_WORDS[1]}" == "remove" ]] && [[ ${#COMP_WORDS[@]} -gt 2 ]];then
     COMPREPLY=($(compgen -W "$(sudo virsh list --name --all)" ${cur}))
  fi
  if [[ "${COMP_WORDS[1]}" == "setip" ]] && [[ ${#COMP_WORDS[@]} -eq 3 ]];then
     COMPREPLY=($(compgen -W "$(sudo virsh list --name)" ${cur}))
  fi
}

if [[ $(type -t compopt) = "builtin" ]]; then
    complete -o default -F __start_vm vm
else
    complete -o default -o nospace -F __start_vm vm
fi
EOF
}

# main 
case "$1" in
    clone)
      shift
      _img=".Rocky.qcow2"
      _xml=".node_base.xml"
      clone_vm ${_img} ${_xml} ${@}
    ;;
    remove)
      while ((${#} > 1));do
        shift
        remove_vm ${1}
      done
    ;;
    setip)
      if (( ${#} == 3 )) && $(sudo virsh list --all --name|grep -Pq "^${2}$");then
         domid=$(sudo virsh domid $2)
         if [[ ${domid} != "-" ]] && $(grep -Pq "^((25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(25[0-5]|2[0-4]\d|1?\d?\d)$" <<<"${3}");then
            vm_setIP "${2}" "$3"
         fi
      else
         echo "${0##*/} setip vm_name ip.xx.xx.xx"
      fi
    ;;
    completion)
      vm_completion
    ;;
    *)
      echo "${0##*/} {clone|remove|setip|completion} vm_name"
    ;;
esac

exit $?

- [root@lindows ~]# more /etc/libvirt/qemu/networks/private1.xml  # 查看private1.xml网络配置

<!--                                                                                                                   
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE                                                
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:                                          
  virsh net-edit private1                                                                                              
or other application using the libvirt API.                                                                            
-->                                                                                                                    
                                                                                                                       
<network>                                                                                                              
  <name>private1</name>                                                                                                
  <uuid>668f46ac-4153-4c0c-8bab-87a0fbd6a930</uuid>                                                                    
  <forward mode='nat'/>                                                                                                
  <bridge name='private1' stp='on' delay='0'/>                                                                         
  <mac address='52:54:00:1f:13:8c'/>                                                                                   
  <domain name='localhost' localOnly='no'/>                                                                            
  <ip address='192.168.88.254' netmask='255.255.255.0'>                                                                
    <dhcp>                                                                                                             
      <range start='192.168.88.128' end='192.168.88.200'/>                                                             
    </dhcp>                                                                                                            
  </ip>                                                                                                                
</network>

- [root@lindows ~]# more /etc/libvirt/qemu/networks/private2.xml  # 查看private2.xml网络配置

<!--                                                                                                                   
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE                                                
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:                                          
  virsh net-edit private2                                                                                              
or other application using the libvirt API.                                                                            
-->                                                                                                                    
                                                                                                                       
<network>                                                                                                              
  <name>private2</name>                                                                                                
  <uuid>3bbe6f7c-f07a-4fe5-a062-f23954864614</uuid>                                                                    
  <bridge name='private2' stp='on' delay='0'/>                                                                         
  <mac address='52:54:00:c9:a6:0a'/>                                                                                   
  <ip address='192.168.99.254' netmask='255.255.255.0'>                                                                
    <dhcp>                                                                                                             
      <range start='192.168.99.128' end='192.168.99.200'/>                                                             
    </dhcp>                                                                                                            
  </ip>                                                                                                                
</network>

-

 

 

end

标签:web,sudo,network,kvm,vm,dev,virsh,null,root
From: https://www.cnblogs.com/lindows/p/17696555.html

相关文章

  • iOS YTKNetworking网络框架增加text/plain支持
    网络请求有时候报错"Requestfailed:unacceptablecontent-type:text/plain"解决办法:在基类初始化时新增以下方法即可-(void)converContentTypeConfig{YTKNetworkAgent*agent=[YTKNetworkAgentsharedAgent];NSSet*acceptableContentTypes=[NSSetsetWithOb......
  • JavaWeb知识学习(一)
    01_HTML&&CSS1.HTMLHTML(HyperTextMarkupLanguage):超文本标记语言特点:HTML文件以.htm或.html为扩展名HTML标签不区分大小写HTML标签属性值单双引皆可HTML语法松散1.1基础标签标题标签<h1>~<h6>换行标签<br>字体标签<font>分割线<hr>段落标签<p>加粗、斜体、下划线标签<b>......
  • Web 应用程序中进行多线程处理-Web Workers
    1、什么是WebWorkers?WebWorkersAPI是一组用于创建并在后台运行脚本的接口,以便在Web应用程序中进行多线程处理。它使得可以将一些耗时的计算任务放在单独的线程中执行,从而避免阻塞主线程,提高了应用程序的响应性能。2、使用方式以下是WebWorkersAPI中常用的接口和方法:......
  • static nat(network address translate)
    核心1、出接口配置natstatic转换,命令如下interfaceGigabitEthernet0/0/1ipaddress20.1.1.1255.255.255.0 natstaticglobal20.1.1.3inside10.1.1.2netmask255.255.255.255natstaticglobal20.1.1.4inside10.1.1.3netmask255.255.255.255注意:此种转换方式......
  • [SpringSecurity5.2.2源码分析七]:WebAsyncManagerIntegrationFilter
    1、作用• 是为了接口返回异步对象,然后执行异步任务也能通过SecurityContextHolder获取SecurityContext• 比如说返回值是WebAsyncTask的时候2、WebAsyncManagerIntegrationFilter• 源码很短就是在WebAsyncManager中注册了SecurityContextCallableProcessingInterceptorpublic......
  • 互联网视频云平台EasyDSS视频服务器无法登录Web页面的排查与解决方法
    EasyDSS互联网视频云服务可支持视频直播、点播,视频直播方面最多可分为十六屏进行实时直播,视频点播方面则有视频点播广场自由点播,灵活性非常强,可满足用户的多场景需求。 我们接收到用户较多的咨询是关于EasyDSS服务运行之后,无法登录Web的情况(如下图)。 排查思路其实遇到这个......
  • webScoket重连机制,心跳机制
    webScoket可以实时获取数据,做到实时渲染的效果,但ws一直连接着还好,万一网络波动,断了呢。。。。那只能刷新页面,重新连接,但又不晓得啥时候断了,这时候就要用到心跳机制,对ws进行监视//WebSocket连接地址constwsUrl=ref('')//Ws实例constws=ref()onMounted(()=>{......
  • web DevOps / engineer day04 /
    s今日总结:环境构建构建Yum仓库开机自动挂载修改UUID内容配置网络参数之主机名配置网络参数之IP地址与子网掩码、网关地址三种方式配置地址:nmcli方式利用nmtui修改IP地址、子网掩码、网关地址(了解)利用配置文件修改IP地址、子网掩码、网关地址(了解)总结(图-15)克隆虚拟机(......
  • react18-webchat网页聊天实例|React Hooks+Arco Design仿微信桌面端
    React18Hooks+Arco-Design+Zustand仿微信客户端聊天ReactWebchat。react18-webchat基于react18+vite4.x+arco-design+zustand等技术开发的一款仿制微信网页版聊天实战项目。实现发送带有emoj消息文本、图片/视频预览、红包/朋友圈、局部模块化刷新/美化滚动条等功能。使用技术......
  • security整合websocket
    快速使用@Configuration@EnableWebSocketMessageBrokerpublicclassWebSocketSecurityConfigextendsAbstractSecurityWebSocketMessageBrokerConfigurer{@AutowiredUserDetailsServiceImpluserDetailsService;@AutowiredRedisTemplate<St......