目录
1、环境准备
本文中的案例会有四台机器,他们的Host和IP地址如下
c1 -> 10.0.0.31
c2 -> 10.0.0.32
c3 -> 10.0.0.33
c4 -> 10.0.0.34
四台机器的host以c1为例:
[root@c1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.31 c1
10.0.0.32 c2
10.0.0.33 c3
10.0.0.34 c4
1.1、Centos 7 64位安装
以c1
安装为示例,安装过程中使用英文版本,然后点击continue
点击LOCALIZATION
下面的Data & Time
,然后选择Asia/shanghai
时区,点击Done
.
点击SYSTEM
下面的INSTALLATION DESTINATION
,选择你的硬盘后,在下面的单选框中,选择I will configure partitioning
点击Done
,我们来自定义硬盘和分区
点击Click here to create them automatically
,系统会自动帮我们创建出推荐的分区格式。
我们将/home的挂载点删除掉,统一加到点/
,文件类型是xfs
,使用全部的硬盘空间,点击Update Settings
,确保后面软件有足够的安装空间。 最后点击左上角的Done
按钮
xfs是在Centos7.0开始提供的,原来的ext4虽然稳定,但最多只能有大概40多亿文件,单个文件大小最大只能支持到16T(4K block size) 的话。而XFS使用64位管理空间,文件系统规模可以达到EB级别。
用于正式生产的服务器,切记必须把数据盘单独分区,防止系统出问题时,保证数据的完整性。比如可以再划分一个,/data专门用来存放数据。
在弹出的窗口中点击Accept Changes
点击下图中的位置,设置机器的Host Name
,这里我们安装机器的Host Name
为c1
最后点击右下角的Begin Installation
,过程中可以设置root的密码,也可以创建其他用户
1.2、网络配置
以下以c1
为例
[root@c1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static #启用静态IP地址
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=e57c6a58-1951-4cfa-b3d1-cf25c4cdebdd
DEVICE=eth0
ONBOOT=yes #开启自动启用网络连接
IPADDR0=192.168.0.31 #设置IP地址
PREFIXO0=24 #设置子网掩码
GATEWAY0=192.168.0.1 #设置网关
DNS1=192.168.0.1 #设置DNS
DNS2=8.8.8.8
重启网络:
[root@c1 ~]# service network restart
更改源为阿里云
[root@c1 ~]# yum insatll -y wget
[root@c1 ~]# cd /etc/yum.repos.d/
[root@c1 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@c1 yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
[root@c1 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@c1 yum.repos.d]# yum clean all
[root@c1 yum.repos.d]# yum makecache
安装网络工具包和基础工具包
[root@c1 ~]# yum install net-tools checkpolicy gcc dkms foomatic openssh-server bash-completion -y
1.3、更改hostname
在四台机器上依次设置hostname,以下以c1
为例
[root@localhost ~]# hostnamectl --static set-hostname c1
[root@localhost ~]# hostnamectl status
Static hostname: c1
Icon name: computer-vm
Chassis: vm
Machine ID: e4ac9d1a9e9b4af1bb67264b83da59e4
Boot ID: a128517ed6cb41d083da61de5951a109
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.36.3.el7.x86_64
Architecture: x86-64
1.4、配置ssh免密码登录登录
先后在四台机器分别执行,以c1
为例
[root@c1 ~]# ssh-keygen
#一路按回车到最后
在免登录端修改配置文件
[root@c1 ~]# vi /etc/ssh/sshd_config
#找到以下内容,并去掉注释符#
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
将ssh-keygen
生成的密钥,分别复制到其他三台机器,以下以c1
为例
[root@c1 ~]# ssh-copy-id c1
The authenticity of host 'c1 (10.0.0.31)' can't be established.
ECDSA key fingerprint is 22:84:fe:22:c2:e1:81:a6:77:d2:dc:be:7b:b7:bf:b8.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@c1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'c1'"
and check to make sure that only the key(s) you wanted were added.
[root@c1 ~]# ssh-copy-id c2
The authenticity of host 'c2 (10.0.0.32)' can't be established.
ECDSA key fingerprint is 22:84:fe:22:c2:e1:81:a6:77:d2:dc:be:7b:b7:bf:b8.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@c2's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'c2'"
and check to make sure tha