使用工具:
1.VMware12 +,
2.CentOS-6.8 / CentOS-7 +,
3.jdk1.8
一、安裝主服務器虛擬機













配置完成,點擊啟動虛擬機!
二、虛擬機網絡設置
需要靜態的方式配置ip,請參考鏈接: 設置靜態IP
(1)重啟網卡服務:
CentOS6.8: # service network restart CentOS7.2: # systemctl restart network.service
(2)CRT遠程連接Linux
(3)禁用SELinux
** Selinux:linux安全管理工具 ** # vi /etc/sysconfig/selinux ** 編輯改動如下: SELINUX:disable
(4)禁用防火牆
** CentOS 6.8 iptables # service iptables stop # chkconfig iptables off ** CentOS 7.2 # systemctl stop firewalld.service # systemctl disable firewalld.service
(5)ping外網測試
ping www.baidu.com
三、分配權限給普通管理員
su - root visudo 添加: shifu(對應賬號) ALL=(ALL) NOPASSWD: ALL

四、修改ip與主機名的映射關系
$ sudo vi /etc/hosts (對應你准備配置的ip) 192.168.1.213 linux01 192.168.1.214 linux02 192.168.1.215 linux03
五、更新yum與安裝samba
參考更新優化linux鏈接:linux軟件優化安裝
參考安裝samba鏈接 :安裝samba
六、安裝JDK
(1)解壓jdk包
在家目錄創建兩個文件夾: cd ~ mkdir -p softwares/installtions mkdir modules 在windows將jdk壓縮包用samba拉到linux的installtions中,解壓到modules中 tar -zxf jdk-8u131-linux-x64.gz -C /home/amidn/modules
(2)配置環境變量
vim /etc/profile 在文件最底部添加: #JAVA_HOME JAVA_HOME=/home/admin/modules/jdk1.8.0_121 export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin 保存后讓配置生效: source /etc/profile
(3)刪除OpenJDK(CentOS 自帶的JAVA環境)
查看相關的自帶java文件: rpm -qa | grep java 用無依賴的方式刪除掉: sudo rpm -e --nodeps (將查詢到的文件復制到這里,一個一個的刪掉)
(4)查看java版本
source /etc/profile java -version 如果是你安裝的版本,就完成啦
七、將linux01,克隆出linux02,linux03
(1)克隆
先關機 sudo shutdown -h now


(2)修改后兩台機器的網絡配置
** 主機名 $ sudo vi /etc/sysconfig/network ** 網卡MAC地址 $ sudo vi /etc/udev/rules.d/70-persistent-net.rules ** IP地址 $ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
(3)使用CRT連接3台機器,測試
八、 配置SSH無秘鑰訪問(如下操作,需要在3台機器中分別執行)
** 生成密鑰,猛點回車 $ ssh-keygen -t rsa ** 分發公鑰 $ ssh-copy-id linux01; ssh-copy-id linux02; ssh-copy-id linux03; ** ssh訪問測試 ssh linux01 ssh linux02 ssh linux03
九、關閉后兩台機器的界面(linux02,linux03)
CentOS6: $ sudo vi /etc/inittab CentOS7: $ sudo systemctl set-default multi-user.target
十、安裝VMTool(只安裝在linux01)



十一、配置時間服務器
(1) 檢查時區
$ date -R
** 如果時區不是+0800東八區區時的話,需要手動糾正
$ sudo rm -rf /etc/localtime
$ sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
(2)檢查軟件包
如果ntp工具不存在,則需要使用yum安裝 $ sudo rpm -qa | grep ntp 如果不存在則安裝: $ sudo yum -y install ntp
(3)先以網絡時間為標准,糾正集群的時間服務器的時間
$ sudo ntpdate pool.ntp.org
(4)修改ntp配置文件
$ sudo vi /etc/ntp.conf 修改為如下: #允許192.168.1.x網段上的所有機器和當前這台機器進行實踐同步 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap #當該節點丟失網絡連接,依然可以作為時間服務器為集群其他節點提供時間同步服務 server 127.127.1.0 fudge 127.127.1.0 stratum 10 # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst
(5)重啟ntp服務
CentOS6: $ sudo chkconfig ntpd on $ sudo service ntpd restart CentOS7: $ sudo systemctl enable ntpd.service $ sudo systemctl restart ntpd.service
注意:出現報錯為:the NTP socket is in use, exiting
解決辦法:
service ntpd stop ntpdate ntp.api.bz
(6)使用從節點,手動同步時間(linux02,linux03)
$ sudo ntpdate linux01
(7)設置時間同步任務(linux02,linux03)
# crontab -e 編輯時間任務 (尖叫提示:上面的#號代表root用戶,下邊的#號代表shell注釋) # .------------------------------------------minute(0~59) # | .----------------------------------------hours(0~23) # | | .--------------------------------------day of month(1~31) # | | | .------------------------------------month(1~12) # | | | | .----------------------------------day of week(0~6) # | | | | | .--------------------------------command # | | | | | | # | | | | | | */10 * * * * /usr/sbin/ntpdate linux01
(8)重啟定時任務
CentOS6: # service crond restart CentOS7: # systemctl restart crond.service
十二、備份配置好的集群、(必須養成定期備份的習慣)
先關機:
$ sudo shutdown -h now
按照時間新建文件夾,將已經安裝完成的3台虛擬機,備份到該文件夾中。
