General method for setting up a VMware virtual machine environment

1. Preparation

1. Download and install a virtual machine software

VMware16 download address
Insert image description here

Tip: There are a lot of information on how to use the free version on the Internet, so I won’t explain it in detail here. When in doubt, ask Baidu

提示:如果下载较慢建议切换其他站点进行下载,目前使用华为现在还是比较快的,推荐下载iso文件,我没有下载everything这种的iso文件,可能和后续安装报错不同,这里没有使用带everything的iso文件做演示

Ali centos7 download address

Insert image description here
Huawei download centos7
Insert image description here

Tip: There are a lot of information on how to use the free version on the Internet, so I won’t explain it in detail here. When in doubt, ask Baidu

Download xshell or other remote tools (if the virtual machine is not troublesome)


2. Start creating a virtual machine

1. Configure virtual machine hardware related operations

Insert image description here
Insert image description here
Insert image description here

Tip: Modify the name of the virtual machine to facilitate subsequent cluster building for differentiation. Change the location to the specified location. I generally like to put it in a solid-state drive. If the solid-state space is tight, put it in a place with sufficient space. It is recommended to have at least 60GB of space. disk.

Insert image description here
Insert image description here

Tip: Set the memory size and configure it according to your actual memory. If you only have 8G of memory, it is recommended to have 1G or less. I have 16G here, so I set it a little larger. Later, I need to build a cluster of three virtual machines with 2G of memory every day. Of course You can also use the configuration disk as memory for subsequent settings.

Insert image description here
提示:设置你下载好的centos7文件
Insert image description here

2. Virtual machine network related operations

注意:设置网络模式为NAT模式
Insert image description here

Open the Windows command line: Enter the following command to query your ipv4 address, subnet mask, gateway, etc. Do not look at the one starting with vm. Here is the network cable. If you are connecting to wifi, choose to bring wireless LAN related content.

ipconfig

Insert image description here

提示:回到vmware,为虚拟机配置网络信息
Insert image description here
Insert image description here
虚拟机配置根据你Windows上的信息配置

For example, my Ipv4 address is 192.168.11.6, then the virtual machine configuration is 192.168.11.0. The subnet mask is 255.255.255.0.

Insert image description here
配置网关
Insert image description here
和你Windows中的ipv4地址一个网段,不要和已经配置的ip地址重复
Set up gateway
Insert image description here

Insert image description here


3. Content related to boot configuration

When you encounter this interface, press Enter directly
Insert image description here

0. Error handling when booting up (select to see – please ignore if there is no error when booting up)

If you encounter this problem, please follow the steps below if

Insert image description here
Step 1
Insert image description here
or click directly
Insert image description here
Step 2 Check the following, save and boot again.
Insert image description here
If it still doesn’t work, select compatible with lower versions.
Step 3
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
and then boot
如果还是不行,比如我就是这个大冤种,尝试更换一下centos7的其它版本镜像。我成功了,更换的是个镜像,去掉之前那些步骤设置的信息哈。我是直接把之前新建的虚拟机删除了,然后新建只是更换的镜像文件,步骤1-3都没有操作
Insert image description here

1. Start configuration

Insert image description here

There is no option to minimize the installation here, because good software requires
Insert image description here
Insert image description here
Insert image description here
Insert image description here

如果内存不足,则使用磁盘充当内存,分配大小4G

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
**记住这个网络地址,后续需要使用他连接xshell**
Insert image description here
Insert image description here
Insert image description here
set root user
Insert image description here

Insert image description here
After waiting for a while, click Restart
Insert image description here

2. Configure after booting

Insert image description here

Do you still remember the IP address you configured the network with before? If you forget, please read below.

Insert image description here
First log in to your virtual machine as the root user and enter your account password. By default, the password does not include the number of digits displayed. Just hit enter when you're done typing

root

Insert image description here
After successful login,
enter

ifconfig

get ip address
Insert image description here

3. Use xshell to log in remotely

Insert image description here
Insert image description here
Insert image description here

连接成功!!!

Insert image description here

4. Use xshell to configure virtual machine network information (complete the stand-alone version)

Disclaimer: The following functions used by linux
1. Edit the content of the file , press the i key on the keyboard to lowercase. 2. Save
the file after modification , step 1 press the esc key to exit the editing mode. Step 2 : Press the colon in the English state. Step 3 wq key lowercase mode. Step 4 Press the enter key to return. 3. Automatically complete the file path or file name by pressing the tab key . Enter part of the file name or path and press the tab key to complete it. 4. After modification, if you find that you do not want to save and want to exit directly : q! Key colon, q, exclamation mark 5. Command There are too many commands in the line operation, if you want to clear the screen, press ctrl+L


Step 1: Edit ifcfg-eno** file
按tab补全后续文件名称,每台电脑的文件名称可能不同

vim /etc/sysconfig/network-scripts/ifcfg-eno

Insert image description here
Enter
Insert image description here

Press the i key to edit
① Modify the content (note that if the value you set does not have double quotes, you do not need to add double quotes. If the original value has double quotes, add double quotes)

BOOTPROTO="static"
ONBOOT="yes"

You can delete these two lines and copy and paste my content into your file
Insert image description here
Insert image description here

②Set the value of the added content
DEVICE and your NAME to the same content

DEVICE="eno16777736"
IPADDR="192.168.11.137"
GATEWAY="192.168.11.2"
NETMASK="255.255.255.0"
DNS1="8.8.8.8"

Save
first press the esc key and then execute the following command

:wq

Step 2. Turn off the firewall and restart the network

systemctl stop firewalld 
systemctl disable firewalld
service network restart

See if you can connect to the Internet normally

ping www.baidu.com

Insert image description here

So far the stand-alone version of the virtual machine has been completed! ! ! !

4. Build a cluster

1. Configure host information

I configured july1

vim /etc/hostname

Insert image description here

2. Register authorized users

Configure the registered new user to have the same permissions as the root user
①Add a new user named july

useradd july
passwd july

Insert image description here
If there are these prompts, please enter the password in july several times.
②Set permissions the same as root and
add modification permissions to the sudoers file.

chmod u+w /etc/sudoers
vim /etc/sudoers

To find this location
Insert image description here
enter the following

july    ALL=(ALL)       NOPASSWD:ALL

Insert image description here

3. Create a storage directory for storing installation packages and software after installation

mkdir /opt/module
mkdir /opt/software

4. Configure the directory to specify the owner

chown july:july /opt/module 
chown july:july /opt/software

Query whether the configuration is successful

cd /opt/
ll

Insert image description here

5. Configure the distribution script

cd /home/july

Create a new bin directory

mkdir bin
cd bin
vim xsync

The content is as follows

Among them, july1 july2 july3 is the host name of the three-day virtual machine. The configuration of 2 and 3 will be added later, please wait.

#!/bin/bash

#1. 判断参数个数
if [ $# -lt 1 ]
then
    echo Not Enough Arguement!
    exit;
fi

#2. 遍历集群所有机器
for host in july1 july2 july3
do
    echo ====================  $host  ====================
    #3. 遍历所有目录,挨个发送

    for file in $@
    do
        #4. 判断文件是否存在
        if [ -e $file ]
            then
                #5. 获取父目录
                pdir=$(cd -P $(dirname $file); pwd)

                #6. 获取当前文件的名称
                fname=$(basename $file)
                ssh $host "mkdir -p $pdir"
                rsync -av $pdir/$fname $host:$pdir
            else
                echo $file does not exists!
        fi
    done
done

Insert image description here
Increase the executable permissions of the script

chmod +x xsync

Configure environment variables for the script.
Create a new my_env.sh file ( 这个文件放在了/etc/profile.d下,相当于自定义一个环境变量的配置,没有在/etc/profile这个下边进行追加修改,效果是一样的)

sudo vim /etc/profile.d/my_env.sh

The input content is as follows

#XSYNC_HOME
export XSYNC_HOME=/home/july
export PATH=$PATH:$XSYNC_HOME/bin

Make environment variables effective

source /etc/profile

Test whether the configured environment variables take effect. The error reported below is normal. Have you configured the distribution script yet?

xsync /home/july/bin

Insert image description here

6. Clone two virtual machines

先关闭当前虚拟机

Start cloning the first

Insert image description here
Insert image description here
Insert image description here

Set the name and save location and click Finish

Insert image description here
开启克隆的虚拟机

ifconfig

Insert image description here
Use xshell to connect.
The account and password are the same as the first one, but the IP address is different.
Modify the network configuration.

vim /etc/sysconfig/network-scripts/ifcfg-eno

Delete the following two lines,
Insert image description here
modify the IP address,
Insert image description here
and restart the network.

service network restart

Test network

ping wwww.baidu.com

modify host

vim /etc/hostname

Insert image description here
克隆第二台虚拟机
Consistent with cloning the first virtual machine, use the first virtual machine to clone virtual machines 2 and 3 respectively
Insert image description here
to connect to xshell.

vim /etc/sysconfig/network-scripts/ifcfg-eno

Restart the network

service network restart

Test network

ping wwww.baidu.com

modify host

vim /etc/hostname

Insert image description here
At this point, the IP addresses of the three virtual machines have been configured,
respectively.

192.168.11.137
192.168.11.139
192.168.11.140

7. Configure mapping addresses for three virtual machines

Each needs to execute and add the same content

vim /etc/hosts

The default content is as follows, add content below
Insert image description here

192.168.11.137 july1
192.168.11.139 july2
192.168.11.140 july3

Insert image description here
After the first unit is configured, configuration will also be required in the next two days.
Use the distribution script to distribute the script file of the first virtual machine to virtual machines 2 and 3.
Use the distribution script for july users.

su july
xsync /home/july/bin

Insert image description here
The password is the July user password you set. If you follow my tutorial, it is July.

Go to the other two virtual machines to see if it is successful

cd /home/july/bin/
ll

Insert image description here

8. Configure and distribute password-free login

每台虚拟机都需要进行配置
switch to this directory

cd  /home/july/.ssh

If there is no such directory, connect remotely

ssh july1

Enter the password july
to exit the remote connection

exit

Start configuring without password

Execute the command below and press Enter all the time

ssh-keygen -t rsa

Insert image description here

ssh-copy-id july1

Enter yesEnter
password

ssh-copy-id july2

Enter yesEnter
password

ssh-copy-id july3

Enter yesEnter
password

Insert image description here
Test surface password-free distribution script
Distribute custom created environment variables to july2 and 3

xsync /etc/profile.d/my_env.sh

Insert image description here
The following commands also need to be executed on 2 and 3 to make the environment variables take effect

source /etc/profile

So far, the password-free distribution is successful. Of course, if you are more rigorous, you need to test whether the distribution is successful on july2 and 3.
Insert image description here
Insert image description here

5. Summary

About building some cluster environments, such as java, kafka and so on. Use the distribution script to configure it on one server, and then distribute it to other services. Then you only need to modify the specified configuration file to complete the deployment of the corresponding environment. The efficiency is much improved, but it is a little troublesome when you click on the cluster for the first time. It provides very high convenience for subsequent cluster building, especially when there are many cluster nodes.

Guess you like

Origin blog.csdn.net/xiaobai_july/article/details/129409995