SSH批量部署服务

1.1在NFS上作为中心分发服务器将私钥分发到其他服务器上

1.1.1NFS部署

 [root@nfs-server ~]# useradd zhurui
[root@nfs-server ~]# echo 123456|passwd --stdin zhurui
Changing password for user zhurui.
passwd: all authentication tokens updated successfully.
创建密码对:
[root@nfs-server ~]# su - zhurui ##切换到zhurui用户下,以后批量分发都在当前用户下,安全考虑
[zhurui@nfs-server ~]$ ssh-keygen -t dsa ##ssh-keygen是生成秘钥的工具,-t参数指建立秘钥的类型,这里建立dsa类型秘钥(还有一种类型的秘钥为RSA,两者加密算法有区别)
Generating public/private dsa key pair.
Enter file in which to save the key (/home/zhurui/.ssh/id_dsa):
Created directory '/home/zhurui/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zhurui/.ssh/id_dsa.
Your public key has been saved in /home/zhurui/.ssh/id_dsa.pub.
The key fingerprint is:
6f:65:c4:a6:fb:32:45:0c:85:c3:bc:87:8f:a4:ae:bc zhurui@nfs-server
The key's randomart image is:
+--[ DSA 1024]----+
| o o. |
| *. |
| *+ |
| +++ |
| So.=o |
| ...+o |
| . +. |
| . ..o. |
| Eo o. |
+-----------------+
[zhurui@nfs-server ~]$
[zhurui@nfs-server ~]$ ls -l .ssh/
total 8
-rw-------. 1 zhurui zhurui 672 Mar 5 04:23 id_dsa ##私钥
-rw-r--r--. 1 zhurui zhurui 607 Mar 5 04:23 id_dsa.pub ##公钥
将公钥分发给web-lamp01服务器
[zhurui@nfs-server ~]$ ssh-copy-id -i .ssh/id_dsa.pub zhurui@192.168.1.12 ##将公钥分发给1.12服务器
The authenticity of host '192.168.1.12 (192.168.1.12)' can't be established.
RSA key fingerprint is d6:e6:e6:2a:c7:df:99:51:bb:f4:90:29:16:df:c4:a5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.12' (RSA) to the list of known hosts.
Nasty PTR record "192.168.1.12" is set up for 192.168.1.12, ignoring
zhurui@192.168.1.12's password:
Permission denied, please try again.
zhurui@192.168.1.12's password:
Now try logging into the machine, with "ssh 'zhurui@192.168.1.12'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [zhurui@nfs-server ~]$

1.1.2 web-lnmp02客户端分发部署

 [zhurui@nfs-server ~]$ ssh-copy-id -i .ssh/id_dsa.pub zhurui@192.168.1.13  ##将公钥分发到1.13服务器
The authenticity of host '192.168.1.13 (192.168.1.13)' can't be established.
RSA key fingerprint is d6:e6:e6:2a:c7:df:99:51:bb:f4:90:29:16:df:c4:a5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.13' (RSA) to the list of known hosts.
Nasty PTR record "192.168.1.13" is set up for 192.168.1.13, ignoring
zhurui@192.168.1.13's password:
Now try logging into the machine, with "ssh 'zhurui@192.168.1.13'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [zhurui@nfs-server ~]$

1.1.3 rsync-backup客户端分发部署

 [zhurui@nfs-server ~]$ ssh-copy-id -i .ssh/id_dsa.pub zhurui@192.168.1.17
The authenticity of host '192.168.1.17 (192.168.1.17)' can't be established.
RSA key fingerprint is d6:e6:e6:2a:c7:df:99:51:bb:f4:90:29:16:df:c4:a5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.17' (RSA) to the list of known hosts.
zhurui@192.168.1.17's password:
Now try logging into the machine, with "ssh 'zhurui@192.168.1.17'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [zhurui@nfs-server ~]$

2.1在NFS上测试

2.1.1 通过ssh命令在当前机器上查看web-lamp01的IP地址

 [zhurui@nfs-server ~]$ ssh -P22 zhurui@192.168.1.12 /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:49:CE:B3
inet addr:192.168.1.12 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe49:ceb3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7701 errors:0 dropped:0 overruns:0 frame:0
TX packets:4795 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4806676 (4.5 MiB) TX bytes:484902 (473.5 KiB)
注:在命令执行过程中,跳过输入密码的步骤
接着分发文件测试:
[zhurui@nfs-server ~]$ cp /etc/hosts
hosts hosts.allow hosts.deny
[zhurui@nfs-server ~]$ cp /etc/hosts .
[zhurui@nfs-server ~]$ ll
[zhurui@nfs-server ~]$ scp -P22 hosts zhurui@192.168.1.12:~ ##将当前目录下hosts文件分发到1.12家目录下
hosts 100% 243 0.2KB/s 00:00
[zhurui@nfs-server ~]$ 检查1.12上zhurui家目录下有无hosts文件
[root@lamp01 zhurui]# cat /home/zhurui/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.11 nfs-server
192.168.1.17 backup
192.168.1.12 lamp01
192.168.1.13 lnmp02
[root@lamp01 zhurui]#
通过脚本分发:
[zhurui@nfs-server ~]$ sh fenfa.sh
hosts 100% 257 0.3KB/s 00:00
hosts 100% 257 0.3KB/s 00:00
hosts 100% 257 0.3KB/s 00:00

批量管理脚本:

 #!/bin/sh
. /etc/init.d/functions
if [ $# -ne 1 ]
then
echo "USAGE:$0 USAGE|COMMAND"
exit 1
fi
for n in 12 13 17
do
ssh -p22 zhurui@192.168.1.$n $1
done ~

批量分发脚本:

 #!/bin/sh
. /etc/init.d/functions for n in 12 13 17
do
scp -P22 $1 zhurui@192.168.1.$n:~ &>/dev/null
if [ $? -eq 0 ]
then
action "fenfa $1 ok" /bin/true
else
action "fenfa $1 ok" /bin/false
fi
done ~

利用分发脚本分发hosts文件

 [zhurui@nfs-server ~]$ sh fenfa.sh hosts
fenfa hosts ok [ OK ]
fenfa hosts ok [ OK ]
fenfa hosts ok [ OK ]
[zhurui@nfs-server ~]$

优化后的分发脚本

 #!/bin/sh
. /etc/init.d/functions
if [ $# -ne 1 ]
then
echo "USAGE:$0 {FILENAME|DIRNAME}"
exit 1
fi
for n in 12 13 17
do
scp -P22 -r $1 zhurui@192.168.1.$n:~ &>/dev/null
if [ $? -eq 0 ]
then
action "fenfa $1 ok" /bin/true
else
action "fenfa $1 ok" /bin/false
fi
done

SSH批量部署服务的更多相关文章

  1. jenkins+ant+ssh远程部署服务glassfish

    jenkins安装可以参考官网或自己百度,这里不再说明: jenkins版本2.19.2 这里先说一下目的:主要是通过jenkins实现glassfish的部署,源码使用的是svn,编译是使用ant, ...

  2. docker~不使用yml批量部署服务

    回到目录 有时,我们在进行持续集成环境有时,有时yml环境是没有的,它可能只提供了docker工具,而docker-compose这个大家伙可能不被提供,而这样我们如果希望自动化构建解决方案下所有的项 ...

  3. Linux(11):期中架构(3)--- SSH远程管理服务 & ansible 批量管理服务

    SSH远程管理服务 1. 远程管理服务知识介绍 # 1.1 SSH远程登录服务介绍说明 SSH是Secure Shell Protocol的简写,由 IETF 网络工作小组(Network Worki ...

  4. Linux服务之批量部署篇

    批量部署步骤: 1.检查环境 getenforce               #检查内核防火墙是否关闭 systemctl status firewalld       #检查firewalld是否 ...

  5. Windows server 2008R2部署服务批量安装Windows7教程

    利用Windows server 2008 R2下的Windows部署服务可以批量安装Windows 7,以下简称WDS. WDS需要用到域和dhcp.DNS服务,所以,基础环境必须要有域控制器,dh ...

  6. 使用Cobbler批量部署Linux和Windows:Cobbler服务端部署(一)

    本文记录了我使用Cobbler批量安装部署Linux和Windows系统的过程,文章主要分为三部分:Cobbler服务端的安装配置.Linux发行版CentOS和Ubuntu的自动安装部署.Windo ...

  7. 批量部署ssh私钥认证

    vim  batch_sshkey.sh #!/bin/bashcd /rootcat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keysfor ...

  8. shell脚本批量部署ssh

    日常运维工作中,需要给几十上百台服务器批量部署软件或者是重启服务器等操作, 这样大量重复性的工作一定很苦恼,本文给大家提供了最基本的批量操作的方法,虽然效率不高,对于初学者来说还是好理解.由于刚开始学 ...

  9. (转)使用Cobbler批量部署Linux和Windows:Cobbler服务端部署(一)

    原文:http://www.cnblogs.com/pluse/p/8316914.html http://blog.51cto.com/dreamway/1166589---------Cobble ...

随机推荐

  1. python获取ip代理列表爬虫

    最近练习写爬虫,本来爬几张mm图做测试,可是爬到几十张的时候就会返回403错误,这是被网站服务器发现了,把我给屏蔽了. 因此需要使用代理IP.为了方便以后使用,我打算先写一个自动爬取ip代理的爬虫,正 ...

  2. 阿里云自定义日记文件无法通过ftp下载

    异常处理汇总 ~ 修正果带着你的Net飞奔吧!http://www.cnblogs.com/dunitian/p/4599258.html 有可能是个例,xftp不行(对linux支持很好),Cute ...

  3. GitHub实战系列~2.把本地项目提交到github中 2015-12-10

    GitHub实战系列汇总:http://www.cnblogs.com/dunitian/p/5038719.html ———————————————————————————————————————— ...

  4. ASP.NET MVC系列:Model

    1. Model任务 Model负责通过数据库.AD(Active Directory).Web Service及其他方式获取数据,以及将用户输入的数据保存到数据库.AD.Web Service等中. ...

  5. 使用 Ghost 写博客

    今天在https://ghost.org/上试用了一会,发现这是一个出色的博客平台,相比WordPress,更轻量级,而且是使用Node.js来做的,性能也是非常的不错. 优点 轻量级 支持主题 支持 ...

  6. OpenNLP:驾驭文本,分词那些事

    OpenNLP:驾驭文本,分词那些事 作者 白宁超 2016年3月27日19:55:03 摘要:字符串.字符数组以及其他文本表示的处理库构成大部分文本处理程序的基础.大部分语言都包括基本的处理库,这也 ...

  7. 【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之RAC 特殊问题和实战经验(五)

    RAC 特殊问题和实战经验(五) 概述:写下本文档的初衷和动力,来源于上篇的<oracle基本操作手册>.oracle基本操作手册是作者研一假期对oracle基础知识学习的汇总.然后形成体 ...

  8. 跟我学习NHibernate (1)

    引言:Nibernate概述 NHibernate是一个ORM框架,NHibernate是一个把C#对象世界和关系世界数据库之间联系起来的一座桥梁.NHibernate 能自动映射实体模型到数据库,所 ...

  9. 一个前端所需具备的PS能力

    前端网页设计+静态实现案例 放一个2天半内给某公司完成的(设计 + 静态实现)的案例吧,静态阴影用CSS3实现的http://www.cnblogs.com/MuYunyun/p/5693615.ht ...

  10. Java对象序列化剖析

    对象序列化的目的 1)希望将Java对象持久化在文件中 2)将Java对象用于网络传输 实现方式 如果希望一个类的对象可以被序列化/反序列化,那该类必须实现java.io.Serializable接口 ...