Test 7

网友投稿 226 2022-11-08

Test 7

1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置)

修改主机名 root@ubuntu1804:~# hostnamectl set-hostname ubuntu1804.magedu.org root@ubuntu1804:~# cat /etc/hostname ubuntu1804.magedu.org root@ubuntu1804:~# hostname ubuntu1804.magedu.org 网卡名称 #修改配置文件为下面形式 root@ubuntu1804:~#vi /etc/default/grub GRUB_CMDLINE_LINUX="net.ifnames=0" #或者sed修改 root@ubuntu1804:~# sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#' /etc/default/grub #生效新的grub.cfg文件 root@ubuntu1804:~# grub-mkconfig -o /boot/grub/grub.cfg #或者 root@ubuntu1804:~# update-grub root@ubuntu1804:~# grep net.ifnames /boot/grub/grub.cfg       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-8c14- fe1a48ba153c ro net.ifnames=0       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a- 8c14-fe1a48ba153c ro net.ifnames=0       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a- 8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0       linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a- 8c14-fe1a48ba153c ro net.ifnames=0       linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a- 8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0 #重启生效 root@ubuntu1804:~# reboot 配置自动获取IP root@ubuntu1804:~# cat /etc/netplan/01-netcfg.yaml # This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets:   eth0:     dhcp4: yes 静态的IP配置 [root07:19 PMubuntu /etc/netplan]#pwd /etc/netplan [root07:10 PMubuntu /etc/netplan]#cat 02-eth1.yaml network: version: 2 renderer: networkd ethernets: eth1: addresses: [192.168.8.10/24,10.0.0.10/8] gateway4: 10.0.0.2 nameservers: search: [magedu.com, magedu.org] addresses: [180.76.76.76, 8.8.8.8, 1.1.1.1] 修改网卡配置文件后需执行命令生效: root@ubuntu1804:~#netplan apply

2、编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)。

expect方式 第一步:编写文件 [root@centos7 scripts]#vim expect #!/usr/bin/expect spawn ssh 10.0.0.18 expect { "yes/no" { send "yes\n";exp_continue } "password" { send "123456\n" } } interact 第二步:加执行权限执行脚本 [root@centos7 scripts]#chmod +x expect [root@centos7 scripts]#./expect spawn ssh 10.0.0.18 root@10.0.0.18's password: Last login: Tue Jun 22 09:57:01 2021 from 10.0.0.17 [root@ ~]#hostname -I 10.0.0.18 10.0.0.118 ===================================================== shell方式 [root@centos7: script]#cat expect6.sh #!/bin/bash ip=$1 user=$2 password=$3 expect <

3、生成10个随机数保存于数组中,并找出其最大值和最小值

[root@centos7 scripts]#cat 37.sh #!/bin/bash declare -i max min declare -a arr for((i=0;i<10;i++));do arr[$i]=$RANDOM [ $i -eq 0 ] && min=${arr[0]} && max=${arr[0]} && continue [ ${arr[$i]} -gt $max ] && max=${arr[$i]} [ ${arr[$i]} -lt $min ] && min=${arr[$i]} done echo "所有的随机数是${arr[*]}" echo "最大值是$max" echo "最小值是$min" [root@centos7 scripts]#bash 37.sh 所有的随机数是14418 15134 15149 3311 21802 20210 32365 23885 840 29108 最大值是32365 最小值是840

4、输入若干个数值存入数组中,采用冒泡算法进行升序或降序排序

[root@centos7 scripts]#cat 38_1.sh #!/bin/bash declare -a nums read -p "请输入生成随机数个数:" number for (( i=0;i<$number;i++ ));do nums[$i]=$RANDOM done echo "before sort:${nums[*]}" declare -i n=$number for (( i=0;i ${nums[$next]} ));then tmp=${nums[$next]} nums[$next]=${nums[$j]} nums[$j]=$tmp fi done done echo "after sort:${nums[*]}" echo "the Min integer is ${nums[0]},the max integer is ${nums[$(( n-1 ))]}"

5、显示统计占用系统内存最多的进程,并排序。

ps -aux |sort -k4nr ps aux --sort=-%mem

6、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!"

#由于使用的是10.0.0.0/24 网段,所以用10.0.0.0/24的测试 方法一 [root@centos7 scripts]#cat 39.sh #!/bin/bash net_ip=10.0.0. for i in {1..255};do { if /bin/ping -c1 -W1 $net_ip$i >/dev/null ;then echo "$net_ip$i is UP success! " else echo "$net_ip$i is DOWN fail! " fi }& done wait 方法二: [root@centos7 scripts]#echo 10.0.0.{1..254} |tr -s " " "\n" > ip.txt [root@centos7 scripts]#cat 40.sh #!/bin/bash while read ip ;do { ping -c1 -W1 $ip >/dev/null [ $? -eq 0 ] && echo "$ip success" || echo "$ip fail" }& done

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:面试再被问到一致性 Hash 算法,这样回答面试官!
下一篇:关于SpringCloud Ribbon替换轮询算法问题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~