VMware快速部署集群

生成原始镜像文件

  1. 使用centos7的mini镜像(例如:CentOS-7-x86_64-Minimal-1908.iso)安装系统,网络设置成**"桥接模式",不勾选"复制物理网络连接状态"**,其他配置可根据实际情况配置。
  2. 系统安装时,关闭"KDUMP",关闭"SECURITY POLICY",安装位置中的磁盘配置可根据自己需求(例如:biosboot大小默认为2048K,/boot大小为1G,其余的全部给/),网络配置中勾选"常规--可用时自动连接到这个网络"。
  3. 配置yum源
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum -y install epel-*
yum makecache
  1. 安装常用软件
yum -y install wget vim 
  1. 关闭在测试环境中不需要的功能
#关闭防火墙
systemctl disable firewalld
# 关闭网络管理
systemctl disable NetworkManager
# 关闭SeLinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  1. 配置网络
    如果忽略此不,克隆的虚拟机会出现IP或MAC冲突等问题
# 编辑网卡配置文件,仅保留以下5行即可
vim /etc/sysconfig/network-scripts/ifcfg-ens32
    TYPE=Ethernet
    BOOTPROTO=dhcp
    NAME=ens32
    DEVICE=ens32
    ONBOOT=yes
# /etc/udev/rules.d/70-persistent-net.rules  # 如果有此文件则删除,没有直接进行下一步
reboot -h
  1. 镜像制作(快照)
shutdown -h now
# 虚拟机--快照--拍摄快照--根据自己喜好起一个霸气侧漏的名字,例如Source
  1. 克隆
    选中虚拟机Source --> 右键 --> 管理 --> 克隆 --> 下一步 --> 现有快照 --> 选择上一步拍着的快照 --> 创建完整克隆 --> 下一步 --> 起一个不一样的名字(比如Master) --> 编辑虚拟机配置 --> 网络适配器 --> 高级 --> MAC地址 --> 生成 --> 确定 --> 然后按照上面的步骤,分别克隆机器inode1、inode2、inode3
    修改MAC地址的方式二(推荐使用此方法):找到虚拟机文件夹中的.vmx文件(例如Master.vmx),用文本工具打开,修改选项ethernet0.generatedAddress的值
  2. 开机测试
    将Master、inode1、inode2、inode3全部开启后登陆,输入命令ip a查看IP是否正常获取,输入ping www.baidu.com查看是否能够正常上网
  3. 使用xshell连接之后开始批量操作

LNMP

如果需要安装nginx、php、mariadb(mysql),则需要继续进行下面的步骤。
关于php和nginx的配置可根据需求进行定制。
关于mariadb只配置了数据和错误日志目录,因为这两块内容是最大的,也是最容易导致爆盘的数据,如果开启慢查询,则需要将慢查询的日志路径也进行相应的修改,至于连接数、缓存等等可根据需求进行定制。

yum源配置

development.repo

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
enabled=1
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
enabled=1
gpgcheck=0

[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=0
enabled=1
 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/$releasever/$basearch
enabled=1
gpgcheck=0

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://download.fedoraproject.org/pub/epel/$releasever/$basearch/debug
enabled=1
gpgcheck=0

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://download.fedoraproject.org/pub/epel/$releasever/SRPMS
enabled=1
gpgcheck=0

[epel-testing]
name=Extra Packages for Enterprise Linux 7 - Testing - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/testing/$releasever/$basearch
enabled=1
gpgcheck=0

[epel-testing-debuginfo]
name=Extra Packages for Enterprise Linux 7 - Testing - $basearch - Debug
baseurl=http://download.fedoraproject.org/pub/epel/testing/$releasever/$basearch/debug
enabled=1
gpgcheck=0

[epel-testing-source]
name=Extra Packages for Enterprise Linux 7 - Testing - $basearch - Source
baseurl=http://download.fedoraproject.org/pub/epel/testing/$releasever/SRPMS
enabled=1
gpgcheck=0

php.repo

[webtatic]
name=Webtatic Repository EL7 - $basearch
baseurl=https://repo.webtatic.com/yum/el7/$basearch/
enabled=1
gpgcheck=0

[webtatic-debuginfo]
name=Webtatic Repository EL7 - $basearch - Debug
baseurl=https://repo.webtatic.com/yum/el7/$basearch/debug/
enabled=1
gpgcheck=0

[webtatic-source]
name=Webtatic Repository EL7 - $basearch - Source
baseurl=https://repo.webtatic.com/yum/el7/SRPMS/
enabled=1
gpgcheck=0

[webtatic-archive]
name=Webtatic Repository EL7 - $basearch - Archive
baseurl=https://repo.webtatic.com/yum/el7-archive/$basearch/
enabled=1
gpgcheck=0

[webtatic-archive-debuginfo]
name=Webtatic Repository EL7 - $basearch - Archive Debug
baseurl=https://repo.webtatic.com/yum/el7-archive/$basearch/debug/
enabled=1
gpgcheck=0

[webtatic-archive-source]
name=Webtatic Repository EL7 - $basearch - Archive Source
baseurl=https://repo.webtatic.com/yum/el7-archive/SRPMS/
enabled=1
gpgcheck=0

[webtatic-testing]
name=Webtatic Repository EL7 - $basearch - Testing
baseurl=https://repo.webtatic.com/yum/el7-testing/$basearch/
enabled=1
gpgcheck=0

[webtatic-testing-debuginfo]
name=Webtatic Repository EL7 - $basearch - Testing Debug
baseurl=https://repo.webtatic.com/yum/el7-testing/$basearch/debug/
enabled=1
gpgcheck=0

[webtatic-testing-source]
name=Webtatic Repository EL7 - $basearch - Testing Source
baseurl=https://repo.webtatic.com/yum/el7-testing/SRPMS/
enabled=1
gpgcheck=0

nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

mariadb.repo

[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.5/centos74-amd64/
enabled=1
gpgcheck=0

php71安装

只安装一些常用扩展,后期如果需要其他扩展,请自行使用yum进行安装。

yum -y install mod_php71w php71w-devel php71w-cli php71w-common \
php71w-fpm  php71w-gd php71w-embedded \
php71w-ldap php71w-mbstring  php71w-mcrypt \
php71w-mysqlnd php71w-opcache php71w-pdo php71w-pdo_dblib \
php71w-soap php71w-xml
systemctl enable php-fpm
systemctl start php-fpm
# 其他常用扩展可以使用yum list *php71*命令来查看

mariadb10.5安装

yum -y install mariadb-server mariadb
mkdir -p /mariadb/{db,log}
chown -R mysql:mysql /mariadb
# 移除默认数据文件
rm -rf /var/lib/mysql  
# 编辑总配置文件(这一步不能少)
vim /etc/my.cnf
    [client-server]
    socket=/mariadb/mysql.sock
# 编辑客户端配置文件
vim /etc/my.cnf.d/mysql-clients.cnf
    [client]
    default-character-set=utf8
# 编辑服务端配置文件
vim /etc/my.cnf.d/server.cnf 
    [mysqld]
    datadir = /mariadb/db
    log_error = /mariadb/log/error.log
    init_connect='SET NAMES utf8'
    character-set-server=utf8
# 初始化数据后启动
mysql_install_db --defaults-file=/etc/my.cnf --datadir=/mariadb/db
systemctl enable mariadb
systemctl start mariadb
# 设置root密码后登陆
vim /usr/bin/mysql_secure_installation
    # 在make_config()函数中的  echo "password='$esc_pass'" >>$config  这行下面添加如下一行
    echo "socket=/mariadb/mysql.sock" >>$config
mysql_secure_installation
    n #是否切换到unix套接字身份验证
    Y #是否设置root密码
    123456  # mariadb中root用户的密码
    123456
    Y #是否删除匿名用户?(就是空用户),建议删除
    Y #是否不允许远程root登录
    Y #是否删除test数据库
    Y #是否加载权限使之生效
mysql -uroot -p
    show databases;
    exit

nginx1.19.2安装

yum -y install nginx
systemctl enable nginx
systemctl start nginx