修改主機(jī)名
> 搭建集群的第一個(gè)工作,得知道每臺(tái)機(jī)器的名字炫惩,也就是給每臺(tái)機(jī)器起名字(后續(xù)通過名字來取得聯(lián)系)
centos 下修改主機(jī)名
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=simon
ubuntu 下修改主機(jī)名
[root@localhost ~]# vim /etc/hostname
simon
搭建dns服務(wù)器(下面是通過host文件來實(shí)現(xiàn)僻弹,真實(shí)環(huán)境中可以DNS來配置)
我們現(xiàn)在需要每臺(tái)服務(wù)器之間可以通信,把每臺(tái)機(jī)器的hosts配置一下
[root@localhost ~]# inconfig 查看IP地址
[root@localhost ~]# vim /etc/hosts
192.168.1.102 ubuntu
192.168.1.102 ms 管理服務(wù)器 添加之末尾
192.168.1.119 db 數(shù)據(jù)庫服務(wù)器
192.168.1.120 test 測試服務(wù)器
192.168.1.121 product 產(chǎn)品服務(wù)器
//添加四臺(tái)服務(wù)器
> 需要重啟服務(wù)器 shutdown -r now
此時(shí)可以通過主機(jī)名來聯(lián)系他嚷,就可以ping通了
[root@simon ~]# ping ubuntu
PING ubuntu (192.168.1.102) 56(84) bytes of data.
64 bytes from ubuntu (192.168.1.102): icmp_seq=1 ttl=64 time=2.16 ms
64 bytes from ubuntu (192.168.1.102): icmp_seq=2 ttl=64 time=0.291 ms
64 bytes from ubuntu (192.168.1.102): icmp_seq=7 ttl=64 time=0.252 ms
--- ubuntu ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6818ms
rtt min/avg/max/mdev = 0.252/0.553/2.163/0.657 ms
服務(wù)器之間互相認(rèn)識(shí)(可以互相傳輸文件 scp拷貝文件)
這里不需要寫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)绾蔚卿浤伢郑课覀內(nèi)绾喂芾砟兀?我們自己必須可以登錄,openssh(我們現(xiàn)在使用的是xshell)我們就必須使用公鑰和私鑰來登錄
ms服務(wù)器:可以登錄扭勉,其他都不能登錄鹊奖,只能在內(nèi)網(wǎng)集群內(nèi)登錄
防火墻設(shè)置只有集群和局域網(wǎng)登錄
還可以使用密鑰登錄
創(chuàng)建密鑰、公鑰的方法
[root@localhost ~]# ssh-keygen -t rsa 后面直接回車即可
Generating public/private 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公鑰 密鑰登錄:拿到公鑰就可以互相登錄
scp id_rsa.pub root@db:~/
scp id_rsa.pub root@test:~/
spc id_rsa.pub root@product:~/
重啟服務(wù)器
ms服務(wù)器來登錄其他服務(wù)器
ssh simon@db;這樣就可以登錄db的服務(wù)器
關(guān)閉密碼登錄(有必要的話忠聚,利用防火墻來設(shè)置)
[root@simon ~]# cd /etc/ssh/
[root@simon ssh]# vim sshd_config
passwordAuthentication on 把yes改成no
需要重啟服務(wù):shutdown -r now
此時(shí)xshell登錄失敗
此時(shí)只有ms服務(wù)器才能登錄
如果ms服務(wù)器掛了的話设哗,就沒辦法登錄其他服務(wù)器了,可以把ms做一個(gè)備份(鏡像 )两蟀,也可以在其他服務(wù)器上做防火墻网梢,讓其他服務(wù)器只能局域網(wǎng)訪問,這樣的話赂毯,我們一個(gè)基本的環(huán)境就OK了
版本庫战虏,測試環(huán)境,產(chǎn)品環(huán)境党涕,文檔庫烦感,自動(dòng)化部署