批量管理服务器,批量分发文件
一、批量管理
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
批量管理服务器,批量分发文件相关推荐
- 小白之-----------shell脚本批量管理服务器
简单思路 (1)创建一个文件file用于存放username,hostIp ,password (2)编写expect,用于登录服务器 (3)编写一个shell脚本,在脚本中循环调用expect程序进 ...
- Expect的安装与应用,及实现自动检测另外一台服务器运行状态并重启,和使用expect脚本远程批量管理服务器与日志分析
学习Expect Expect是什么? Expect是一个免费的编程工具语言,用来实现自动和交互式任务进行通信,而无需人的干预. Expect是不断发展的,随着时间的流逝,其功能越来越强大,已经成为 ...
- vnc远程控制软件配置,如何配置vnc远程控制软件实现批量管理服务器
应该有不少小伙伴在日常工作过程中,都会有关于vnc远程控制软件配置的困扰吧.下载好了软件,却不知道如何使用.那你对vnc远程控制软件配置了解多少呢?又是如何配置vnc远程控制软件实现批量管理服务器的呢 ...
- 云端批量管理服务器平台-旗鱼云梯
现在很多站长的网站不少,都是百度买一台,阿里买两台,腾讯买一台,比较分散化,为了兼顾不同的网站或小程序,买了很多不同厂家服务器,之前的管理肯定是使用一台上一台服务器上设置,如果要设置另一台还要打IP地 ...
- 如何批量运维服务器论文,win 服务器 批量管理 服务器运维利器
由于做服务器运维方面的工作,需要一人对近千台服务器进行统一集中的管理,如同时批量对服务器执行相关的指令.同时批量对LINUX服务器upload程序包.同时批量对LINUX服务器download程序包. ...
- linux 批量启动服务器,批量部署Linux操作系统systemimager 使用
systemimager 可以把一个所有软件都安装完成的系统(黄金客户端)镜像到server 端, 在通过PXE 启动,再同过rsync同步到裸机上 因为systemimager大部分由perl编写, ...
- github 批量管理项目 批量删除项目
github 批量批量删除项目 油猴 脚本 一. 安装方法: 二. 使用方法 以前github见到一个不错的项目就fork,都快成习惯了,导致github里面1400多个项目,需要清理了的时候愁了. ...
- 大规模的服务器如何管理--批量管理工具
作为服务器运维人员都知道,日常检查和处理服务器问题几乎占据了所有时间,检查服务器的繁琐也只有他们自己能体会,这时候,要是能有个工具能帮助他们,就如雪中送炭啊.刚刚好,市面上确实出来了这么几款管理工具, ...
- python 文件更新_使用Python批量更新服务器文件【新手必学】
买了个Linux服务器,Centos系统,装了个宝塔搭建了10个网站,比如有时候要在某个文件上加点代码,就要依次去10个文件改动,虽然宝塔是可视化页面操作,不需要用命令,但是也麻烦,虽然还有git的h ...
最新文章
- 《iOS 6高级开发手册(第4版)》——1.11节秘诀:获取和使用设备姿势
- spring中关于aop拦截功能的记录
- spring的发展||springboot和微服务的介绍
- Python内置函数(30)——super
- 果断收藏!六大主流大数据采集平台架构分析
- arthas 排查内存溢出_Java程序线上故障排查
- C++函数后置返回类型
- 第12章 存储器的保护
- 查看SQL执行计划的方法及优劣
- DOM介绍~超好理解的哦
- linux python pymssql,如何在UbuntuLinux上将pymssql安装到Python3.4而不是2.7?
- Ubuntu20.04安装搜狗输入法指南
- 批量保存网页_一键下载网页所有图片,把美丽存下来
- 广联达登录显示服务器异常求回答,求助【服务器异常】
- 企业微信三方开发(一):回调验证及重要参数获取
- keil警告提示: last line of file ends without a newline
- TiDB | TiDB在5A级物流企业核心系统的应用与实践
- 【安全测试】什么是安全测试
- FTP服务器的配置,以及配置ftp支持ftps
- 河道水面漂浮物检测系统 YOLOv7
热门文章
- Android自定义水波纹动画Layout
- Visual Studio 使用 Web Deploy 发布远程站点
- ftp 客户端 上传
- 常用模块和面向对象 类
- MATLAB读取写入文本数据最佳方法 | Best Method for Loading Saving Text Data Using MATLAB
- qsort函数的用法
- mysql数据库千万级别数据的查询优化和分页测试
- Windows下svn客户端和服务器的安装使用
- 【代码真相】函数调用 堆栈
- 使用sun.net.ftp.FtpClient进行上传功能开发,在jdk1.7上不适用问题的解决