Table of contents
- 1. Preparation
- 2. Start creating a virtual machine
- 3. Content related to boot configuration
- 4. Build a cluster
-
- 1. Configure host information
- 2. Register authorized users
- 3. Create a storage directory for storing installation packages and software after installation
- 4. Configure the directory to specify the owner
- 5. Configure the distribution script
- 6. Clone two virtual machines
- 7. Configure mapping addresses for three virtual machines
- 8. Configure and distribute password-free login
- 5. Summary
1. Preparation
1. Download and install a virtual machine software
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文件做演示
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
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.
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.
提示:设置你下载好的centos7文件
2. Virtual machine network related operations
注意:设置网络模式为NAT模式
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
提示:回到vmware,为虚拟机配置网络信息
虚拟机配置根据你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.
配置网关
和你Windows中的ipv4地址一个网段,不要和已经配置的ip地址重复
Set up gateway
3. Content related to boot configuration
When you encounter this interface, press Enter directly
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
Step 1
or click directly
Step 2 Check the following, save and boot again.
If it still doesn’t work, select compatible with lower versions.
Step 3
and then boot
如果还是不行,比如我就是这个大冤种,尝试更换一下centos7的其它版本镜像。我成功了,更换的是个镜像,去掉之前那些步骤设置的信息哈。我是直接把之前新建的虚拟机删除了,然后新建只是更换的镜像文件,步骤1-3都没有操作
1. Start configuration
There is no option to minimize the installation here, because good software requires
如果内存不足,则使用磁盘充当内存,分配大小4G
**记住这个网络地址,后续需要使用他连接xshell**
set root user
After waiting for a while, click Restart
2. Configure after booting
Do you still remember the IP address you configured the network with before? If you forget, please read below.
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
After successful login,
enter
ifconfig
get ip address
3. Use xshell to log in remotely
连接成功!!!
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
Enter
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
②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
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
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
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
enter the following
july ALL=(ALL) NOPASSWD:ALL
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
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
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
6. Clone two virtual machines
先关闭当前虚拟机
Start cloning the first
Set the name and save location and click Finish
开启克隆的虚拟机
ifconfig
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,
modify the IP address,
and restart the network.
service network restart
Test network
ping wwww.baidu.com
modify host
vim /etc/hostname
克隆第二台虚拟机
Consistent with cloning the first virtual machine, use the first virtual machine to clone virtual machines 2 and 3 respectively
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
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
192.168.11.137 july1
192.168.11.139 july2
192.168.11.140 july3
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
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
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
ssh-copy-id july1
Enter yesEnter
password
ssh-copy-id july2
Enter yesEnter
password
ssh-copy-id july3
Enter yesEnter
password
Test surface password-free distribution script
Distribute custom created environment variables to july2 and 3
xsync /etc/profile.d/my_env.sh
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.
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.