批量管理服务器,批量分发文件

简介:
原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://navyaijm.blog.51cto.com/4647068/835309

一、批量管理

1.配置问密码登陆

[root@localhost ~]# ssh-keygen -t dsa(生成密钥)
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
21:e3:80:d8:34:10:6c:26:8b:4c:72:fc:02:26:e5:8d root@localhost.localdomain
[root@localhost ~]#

[root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub 119.147.146.245(拷贝公钥到要登陆的服务器)
15
The authenticity of host '119.147.146.245 (119.147.146.245)' can't be established.
RSA key fingerprint is ba:7d:60:44:63:6c:f6:6a:9b:4b:ad:94:1b:98:2b:58.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '119.147.146.245' (RSA) to the list of known hosts.
root@119.147.146.245's password: 
Now try logging into the machine, with "ssh '119.147.146.245'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

 

[root@localhost ~]# ssh 119.147.146.245 ifconfig(远程查看单台服务器的IP)
eth0      Link encap:Ethernet  HWaddr 00:50:56:88:0F:01  
          inet addr:119.147.146.245  Bcast:119.147.146.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe88:f01/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:18264423 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1716785 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:7166025790 (6.6 GiB)  TX bytes:162270128 (154.7 MiB)
          Base address:0x2000 Memory:d8920000-d8940000

远程查看多台服务器的信息箱

[root@localhost tmp]# echo 119.147.146.245 >>iplist(生成IP列表)

[root@localhost tmp]# echo 119.147.146.249 >>iplist

[root@localhost tmp]# echo 119.147.146.248 >>iplist

[root@localhost tmp]# vi manger.sh(撰写脚本)


#!/bin/bash
for ip in `cat iplist`
do
        echo "$ip----------------------------------------"
        ssh $ip $1
done
 

[root@localhost tmp]# sh manger.sh df -h(远程查看多台服务器的硬盘信息)
119.147.146.245----------------------------------------
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroupRoot-LogVolRoot
                      14093368   3488436   9877484  27% /
/dev/sda1               101086     19012     76855  20% /boot
tmpfs                   513468         0    513468   0% /dev/shm
/dev/sda5             53050708    185320  50170488   1% /mfsdata1
/dev/sda6             39065388    968620  36112344   3% /mfsdata2
/dev/sda7             39998020    968620  36997584   3% /mfsdata3
119.147.146.249----------------------------------------
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroupRoot-LogVolRoot
                      10125560   3941852   5661060  42% /
/dev/mapper/VolGroupData-LogVolData
                      14220336    553532  12932804   5% /data
/dev/mapper/VolGroupData-LogVolLogs
                       4951688    141196   4554904   4% /data/logs
/dev/sda1               101086     12922     82945  14% /boot
tmpfs                   513068         0    513068   0% /dev/shm
119.147.146.248----------------------------------------
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroupRoot-LogVolRoot
                      10125560   4159936   5442976  44% /
/dev/mapper/VolGroupData-LogVolData
                      14220336    189528  13296808   2% /data
/dev/mapper/VolGroupData-LogVolLogs
                       4951688    141208   4554892   4% /data/logs
/dev/sda1               101086     21349     74518  23% /boot
tmpfs                   513068         0    513068   0% /dev/shm

 

[root@localhost tmp]# sh manger.sh free -m(远程查看多台服务器的内存使用情况)
119.147.146.245----------------------------------------
             total       used       free     shared    buffers     cached
Mem:       1026936     885652     141284          0      68036     711216
-/+ buffers/cache:     106400     920536
Swap:      4194296        108    4194188
119.147.146.249----------------------------------------
             total       used       free     shared    buffers     cached
Mem:       1026140    1016284       9856          0     154076     690928
-/+ buffers/cache:     171280     854860
Swap:      1052248         88    1052160
119.147.146.248----------------------------------------
             total       used       free     shared    buffers     cached
Mem:       1026140     977656      48484          0      48076     758976
-/+ buffers/cache:     170604     855536
Swap:      1052248          8    1052240

 

[root@localhost tmp]# sh manger.sh "useradd admin"(批量建用户)
119.147.146.245----------------------------------------
119.147.146.249----------------------------------------
119.147.146.248----------------------------------------

[root@localhost tmp]# sh manger.sh "echo 'king+5688'|passwd --stdin admin"(批量更改密码)
119.147.146.245----------------------------------------
Changing password for user admin.
passwd: all authentication tokens updated successfully.
119.147.146.249----------------------------------------
Changing password for user admin.
passwd: all authentication tokens updated successfully.
119.147.146.248----------------------------------------
Changing password for user admin.
passwd: all authentication tokens updated successfully.

 

二、批量分发

[root@localhost tmp]# cat fenfa.sh (撰写脚本)
#!/bin/bash
for ip in `cat iplist`
do
        echo "$ip----------------------------------------"
        scp -r -p $1 $ip $2
done

 

[root@localhost tmp]# sh fenfa.sh /etc /tmp/(把/etc目录拷贝到多台远程服务器上的/tmp下

[root@localhost tmp]# ls(验证)
etc

三、通过普通用户实现远程分发文件,远程管理

1.新建普通用户admin 密码:123456

[root@localhost tmp]# sh manger.sh "useradd admin"(批量建用户)
119.147.146.245----------------------------------------
119.147.146.249----------------------------------------
119.147.146.248----------------------------------------

2.生成密钥拷贝到对端

[admin@localhost ~]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/admin/.ssh/id_dsa): 
Created directory '/home/admin/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/admin/.ssh/id_dsa.
Your public key has been saved in /home/admin/.ssh/id_dsa.pub.
The key fingerprint is:
00:1f:1c:fa:a2:e0:79:cc:a4:24:92:47:de:3e:bf:fb admin@localhost.localdomain

 

[admin@localhost .ssh]$ ssh-copy-id -i id_dsa.pub 119.147.146.245
10
The authenticity of host '119.147.146.245 (119.147.146.245)' can't be established.
RSA key fingerprint is ba:7d:60:44:63:6c:f6:6a:9b:4b:ad:94:1b:98:2b:58.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '119.147.146.245' (RSA) to the list of known hosts.
admin@119.147.146.245's password: 
Now try logging into the machine, with "ssh '119.147.146.245'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
 

3.撰写脚本(和上面的一样)

[admin@localhost ~]$ ls
fenfa.sh  iplist  manger.sh

4.测试

拷贝本地的/etc目录到多台远程服务器的/tmp目录下

[admin@localhost ~]$ su - root /home/admin/fenfa.sh /etc /tmp
Password: (输入root密码)
119.147.146.245----------------------------------------
mime.types                                                       100%   14KB  13.8KB/s   00:00    
virc                                                             100% 1533     1.5KB/s   00:00    
.bashrc                                                          100%  124     0.1KB/s   00:00    
.bash_profile                                                    100%  176     0.2KB/s   00:00    
.bash_logout                                                     100%   33     0.0KB/s   00:00    
.zshrc                                                           100% 658     0.6KB/s   00:00  

查看远程服务器内存使用情况

[admin@localhost ~]$ su - root /home/admin/manger.sh "free -m"
Password: (输入root密码)
119.147.146.245----------------------------------------
             total       used       free     shared    buffers     cached
Mem:          1002        966         36          0         86        756
-/+ buffers/cache:        123        879
Swap:         4095          0       4095
119.147.146.249----------------------------------------
             total       used       free     shared    buffers     cached
Mem:          1002        951         50          0        146        676
-/+ buffers/cache:        129        872
Swap:         1027          0       1027
119.147.146.248----------------------------------------
             total       used       free     shared    buffers     cached
Mem:          1002        962         40          0         60        739
-/+ buffers/cache:        162        839
Swap:         1027          0       1027

其实用普通用户做批量管理,批量分发就是多了一步输入root的密码的步骤,这样做的目的是为了安全

本文出自 “屌丝运维男” 博客,请务必保留此出处http://navyaijm.blog.51cto.com/4647068/835309

目录
相关文章
|
1月前
|
存储 监控 固态存储
【vSAN分布式存储服务器数据恢复】VMware vSphere vSAN 分布式存储虚拟化平台VMDK文件1KB问题数据恢复案例
在一例vSAN分布式存储故障中,因替换故障闪存盘后磁盘组失效,一台采用RAID0策略且未使用置备的虚拟机VMDK文件受损,仅余1KB大小。经分析发现,该VMDK文件与内部虚拟对象关联失效导致。恢复方案包括定位虚拟对象及组件的具体物理位置,解析分配空间,并手动重组RAID0结构以恢复数据。此案例强调了深入理解vSAN分布式存储机制的重要性,以及定制化数据恢复方案的有效性。
54 5
|
20天前
|
Linux
Linux 服务器下载百度网盘文件
本教程指导如何使用 `bypy` 库从百度网盘下载文件。首先通过 `pip install bypy` 安装库,接着运行 `bypy info` 获取登录链接并完成授权,最后将文件置于指定目录并通过 `bypy downdir /Ziya-13b-v1` 命令下载至本地。
26 1
Linux 服务器下载百度网盘文件
|
16天前
|
弹性计算 负载均衡 监控
slb分发流量到ecs一般是如何判断?
【9月更文挑战第1天】
31 1
|
1月前
|
PHP
PHP遍历文件并同步上传到服务器
在进行网站迁移时,由于原网站的图片文件过多,采用打包下载再上传的方式耗时过长,且尝试使用FTP工具从旧服务器传输至新服务器时失败。为解决此问题,特使用PHP编写了一款工具,该工具能扫描指定目录下的所有`.webp`图像文件,并将其上传至新的服务器,极大地提高了迁移效率。
71 16
|
27天前
|
存储 安全 文件存储
【服务器数据恢复】Apple苹果Xsan文件系统卷宗误操作导致文件丢失数据恢复案例
客户因误操作删除了macOS服务器上的重要图片和视频文件,需紧急恢复。Xsan文件系统作为苹果专为高负载环境设计的64位簇文件系统,在未有专门恢复工具的情况下,常规RAW恢复仅能提取小部分连续存储的小文件,且无目录结构。通过专业的数据恢复流程,包括安全挂载、阵列重组,并使用专用工具解析文件系统以恢复目录结构,最终成功恢复丢失的文件。此案例突显了Xsan文件系统的特点及其恢复难度。
23 1
|
1月前
|
开发工具 git iOS开发
服务器配置Huggingface并git clone模型和文件
该博客提供了在服务器上配置Huggingface、安装必要的工具(如git-lfs和huggingface_hub库)、登录Huggingface以及使用git clone命令克隆模型和文件的详细步骤。
70 1
|
19天前
|
数据可视化 Python
通过python建立一个web服务查看服务器上的文本、图片、视频等文件
通过python建立一个web服务查看服务器上的文本、图片、视频等文件
19 0
|
1月前
|
安全 Linux Shell
Linux服务器 /etc/pam.d目录下的文件都是什么作用?
【8月更文挑战第2天】Linux服务器 /etc/pam.d目录下的文件都是什么作用?
149 2
|
1月前
|
存储 Ubuntu Linux
如何在服务器之间同步文件?
如何在服务器之间同步文件?
62 3
|
2月前
|
弹性计算 开发工具 云计算
云服务器 ECS产品使用问题之vim 路径提示找不到文件,该如何解决
云服务器ECS(Elastic Compute Service)是各大云服务商阿里云提供的一种基础云计算服务,它允许用户租用云端计算资源来部署和运行各种应用程序。以下是一个关于如何使用ECS产品的综合指南。

热门文章

最新文章