服務(wù)器集群搭建竿屹、管理报强、快速部署
1.修改主機(jī)名
搭建集群的第一個(gè)工作,得知道每臺(tái)主機(jī)的名字拱燃,也就是給每臺(tái)機(jī)器起名字(后續(xù)通過(guò)名字來(lái)取得聯(lián)系)
centos 下修改主機(jī)名
[root@localhost ~]# vim /etc/sysconfig/newwork
NETWORKING = yes
HOSTNAME = simon
ubuntu 下修改主機(jī)名
[root@localhost ~]# vim /etc/hostname
simon
2.搭建dns服務(wù)器(下面是通過(guò)修改host文件來(lái)實(shí)現(xiàn)秉溉,真是環(huán)境中可以DNS來(lái)配置)
我們現(xiàn)在需要每臺(tái)服務(wù)器之間可以通信,把每臺(tái)機(jī)器的hosts配置一下:
[root@localhost ~]# ifconfig //查看IP地址
[root@localhost ~]# vim /etc/hosts
192.168.1.104 //ubuntu
192.168.1.104 ms //管理服務(wù)器 添加到末尾
192.168.1.119 db //數(shù)據(jù)庫(kù)服務(wù)器
192.168.1.120 test //測(cè)試服務(wù)器
192.168.1.121 product //產(chǎn)品服務(wù)器
注:需要重啟服務(wù)器(shutdown -r now),然后就可以通過(guò)主機(jī)名來(lái)聯(lián)系了
[root@simon ~]# ping ubuntu
PING ubuntu (192.168.1.104) 56(84) bytes of data.
64 bytes from ubuntu (192.168.1.104):icmp_sep=1 ttl=64 time=2.16 ms
64 bytes from ubuntu (192.168.1.104):icmp_sep=2 ttl=64 time=0.291 ms
64 bytes from ubuntu (192.168.1.104):icmp_sep=7 ttl=64 time=0.252 ms
//ubuntu ping statistics
7 packets transmitted, 7 recerved,0% packet loss,time 6818ms
rtt min/avg/max/mdev = 0.252/0.553/2.163/0.657 ms
3.服務(wù)器之間互相認(rèn)識(shí)(可以相互傳輸文件scp拷貝文件)
//這里不需要寫(xiě)IP地址 myuser 是ubuntu服務(wù)器的用戶名
[root@simon ~]# scp ./install.log myuser@ubuntu:/home/
產(chǎn)品服務(wù)器的IP是直接暴露在外的碗誉,不安全召嘶,為了安全就要把密碼登陸關(guān)閉掉(db,test,product),但是我們關(guān)閉密碼登陸了,我們又是如何登陸的呢哮缺?我們?nèi)绾喂芾砟嘏课覀冏约罕仨毧梢缘顷懓。琽penssh(我們現(xiàn)在使用的是XSHELL)我們就必須使用公鑰和私鑰來(lái)登陸
ms 服務(wù)器:可以登陸 其他都不能登陸尝苇,只能在內(nèi)網(wǎng)集群內(nèi)登陸
防火墻來(lái)設(shè)置只有集群或局域網(wǎng)登陸
還可以使用密鑰登陸
4.創(chuàng)建密鑰铛只、公鑰的方法:
[root@localhost ~]# ssh-keygen -t rsa //后面直接回車即可
Generating public/pricate rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): //密鑰生成的位置
Created directory '/root/.ssh'.
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:
2f:27:12:19:c4:16:e6:16:6a:24:0c:5e:3a:43:26:e3 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|+=....=. |
|*.+o =o. |
| E o.+ |
| o. . o |
| o S |
| . . |
| . o o |
| . + |
| |
+-----------------+
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog
[root@localhost ~]# cd ./.ssh/
[root@localhost .ssh]# ls
id_rsa id_rsa.pub
[root@localhost .ssh]# cat id_rsa.pub >> authorized_keys
[root@localhost .ssh]# ls
authorized_keys id_rsa id_rsa.pub
[root@localhost .ssh]# cp id_rsa /home/ //把私鑰復(fù)制到/home下,以便下載到本地
id_rsa 私鑰 id_rsa.pub 公鑰 茎匠,密碼登陸:拿到公鑰就可以互相登陸
把公鑰上傳到其他三個(gè)服務(wù)器(db,test,product)
scp id_rsa.pub root@db:~/
scp id_rsa.pub root@test:~/
scp id_rsa.pub root@product:~/
重啟服務(wù)器
ms 服務(wù)器來(lái)登陸其他服務(wù)器
ssh simon@db格仲;//這樣就能登陸db的服務(wù)器了
5.關(guān)閉密碼登陸(有必要的話,利用防火墻來(lái)設(shè)置)
[root@simon ~]# cd /ect/ssh/
[root@simon ssh]# vim sshd_config
PasswordAuthentication on //把yes改成on