Linux运维利器之ClusterShell

回复 收藏
Linux运维利器之ClusterShell

今天看到微博上有技术推荐关于ClusterShell的我就细心看了下,感觉他们写的一点都详细于是心生想写一点关于ClusterShell的知识。

现在运维2.0的时代来了,危机与机遇并存!作为一心想成为运维工程师的我,要不断的学习掌握好一些有用的技能才能走向运维的新战场。
互联网的发展速度已经快到不行了,服务器的数量越来越多管理起来肯定会很痛苦ClusterShell会让你稍微欣慰点。废话不多说上干货!!!

1,ClusterShell的安装:

源码安装:

[root@server2 ~]# wget http://ncu.dl.sourceforge.net/project/clustershell/clustershell/1.6/clustershell-1.6.tar.gz

[root@server2 ~]# tar zxf clustershell-1.6.tar.gz

[root@server2 ~]# cd clustershell-1.6

[root@server2 clustershell-1.6]# python setup.py  install
Traceback (most recent call last):
  File "setup.py", line 35, in
    from setuptools import setup, find_packages
ImportError: No module named setuptools
出错了,不会吧,仔细一看缺少python-setuptools这个模块,只需yum安装即ok!

[root@server2 clustershell-1.6]# yum install -y  python-setuptools

[root@server2 clustershell-1.6]# python setup.py  install

最后三行:
Installed /usr/lib/python2.6/site-packages/ClusterShell-1.6-py2.6.egg
Processing dependencies for ClusterShell==1.6
Finished processing dependencies for ClusterShell==1.6
表示安装ok了。

2,ClusterShell的配置:

[root@server2 clustershell-1.6]# cp conf/*   /etc/clustershell/

clush.conf  groups   groups.conf

[root@server2 clustershell]# vim groups
添加:
server:  server_1   server_3

server:表示组,server_1,2,3分别为server组的主机别名或者主机名。


3,免密码登录server1,server3配置:

[root@server2 ~]# vim /etc/hosts
192.168.217.134  server1
192.168.217.140  server3

生成公钥,私钥。
[root@server2 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
69:3a:e6:20:ca:97:89:99:00:19:07:2c:f1:f9:76:6f root@server2.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|+o               |
|oo..             |
|.+o              |
|o  .     .       |
|.   o . S        |
|.  . . +         |
|. = + + E        |
|.= = + o         |
|...   .          |
+-----------------+
分别传递公钥给server1,server3
[root@server2 ~]# ssh-copy-id  -i ~/.ssh/id_rsa.pub  root@server1
The authenticity of host 'server1 (192.168.217.134)' can't be established.
RSA key fingerprint is be:57:c8:5e:9d:e6:8e:32:09:c0:eb:04:52:e4:ac:0e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server1' (RSA) to the list of known hosts.
root@server1's password:
Now try logging into the machine, with "ssh 'root@server1'", and check in:

  .ssh/authorized_keys

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

[root@server2 ~]# ssh-copy-id  -i ~/.ssh/id_rsa.pub  root@server3
The authenticity of host 'server3 (192.168.217.140)' can't be established.
RSA key fingerprint is 25:81:62:01:30:34:4b:aa:05:d0:b5:ed:fe:7f:a7:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server3' (RSA) to the list of known hosts.
root@server3's password:
Now try logging into the machine, with "ssh 'root@server3'", and check in:

  .ssh/authorized_keys

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

Server2现在是我们的工作环境,首次登录server1,server3会需要输入所对应主机的root密码,从第二次开始就能免密码登录连接了。
这里需要再次确认server2登录server1,server3是否需要密码,如果不需要说明ok。
每配置好一台免密码登录的服务器,最好手动实际操作一下,因为第一次连接会要求手动确认是否保存信息到~/.ssh/known_hosts文件。

4,config配置:
[root@server2 ~]# vim /root/.ssh/config

Host server1
Hostname server1
User root
Port  22

Host server3
Hostname server3
User root
Port  22

【clush有几个比较重要的参数:】 -b : 相同输出结果合并 ,-w : 指定节点 ,-a : 所有节点, -g : 指定组, --copy : 群发文件

测试:1
[root@server2 ~]# clush  -b -g server "uptime"
---------------
server1
---------------
19:26:50 up 9 min,  1 user,  load average: 0.00, 0.02, 0.00
---------------
server3
---------------
19:26:46 up  1:47,  1 user,  load average: 0.00, 0.00, 0.00



测试:2

[root@server2 ~]# clush  -b -g server "ifconfig eth0"
---------------
server1
---------------
eth0      Link encap:Ethernet  HWaddr 00:0C:29:2E:0C:E4
          inet addr:192.168.217.134  Bcast:192.168.217.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe2e:ce4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:181 errors:0 dropped:0 overruns:0 frame:0
          TX packets:172 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:29399 (28.7 KiB)  TX bytes:29106 (28.4 KiB)

---------------
server3
---------------
eth0      Link encap:Ethernet  HWaddr 00:0C:29:DB:E2:BD
          inet addr:192.168.217.140  Bcast:192.168.217.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fedb:e2bd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1800 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1789 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:442117 (431.7 KiB)  TX bytes:263492 (257.3 KiB)
QQ截图20151203111444.png


图片1.png
2015-05-12 19:54 举报
已邀请:
0

tangenxin

赞同来自:

顶一个

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: