How to configure the experimental environment for a simple start of a Linux virtual machine and one-click deployment of shell scripts (to avoid unnecessary and redundant errors)

Experimental environment configuration Linux simple start

1. Turn off the firewall

[root@localhost ~]# systemctl stop firewalld      //关闭防火墙
[root@localhost ~]# systemctl disabled firewalld    //开机不自动启动

2. Turn off core protection

[root@localhost ~]# vi /etc/selinux/config //编辑核心防护的配置文件
......
SELINUX=disabled     //改为disabled,开机不自启
......
[root@localhost ~]# setenforce 0     //关闭核心防护

3. Configure the IP address

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33   //编辑网卡配置文件
......
BOOTPROTO=static     //设置为静态IP地址
......
ONBOOT=yes      //设置开机自启
IPADDR=20.0.0.20     //设置静态IP地址
NETMASK=255.255.255.0  //设置子网掩码
GATEWAY=20.0.0.2    //设置网关
DNS1=8.8.8.8      //设置DNS域名 ,计算机访问外网必须要设置
DNS2=114.114.114.114

4. Mount the CD to a fixed directory

First, check the CD connection in the virtual machine settings (if it is not checked in the virtual machine settings, it cannot be mounted in the system)

 CD mount

[root@localhost ~]# mount /dev/cdrom /mnt   //手动挂载
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# vi /etc/fstab
......
......
/dev/cdrom /mnt iso9660 defaults 0 0  //自动挂载  最后一行手动输入挂载固定格式 
//将光盘挂载到/mnt目录下  开机自动挂载  
[root@localhost ~]# df -Th        //查看系统挂载信息
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root xfs        50G  3.6G   47G    8% /
devtmpfs                devtmpfs  3.8G     0  3.8G    0% /dev
tmpfs                   tmpfs     3.9G     0  3.9G    0% /dev/shm
tmpfs                   tmpfs     3.9G  9.6M  3.9G    1% /run
tmpfs                   tmpfs     3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  179M  836M   18% /boot
/dev/mapper/centos-home xfs       142G   37M  142G    1% /home
tmpfs                   tmpfs     781M  4.0K  781M    1% /run/user/42
tmpfs                   tmpfs     781M   40K  781M    1% /run/user/0
/dev/sr0                iso9660   4.3G  4.3G     0  100% /mnt    //挂载成功

5. Configure server YUM source warehouse

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
总用量 28
-rw-r--r--. 1 root root 1664 8月  30 2017 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 8月  30 2017 CentOS-CR.repo
-rw-r--r--. 1 root root  649 8月  30 2017 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 8月  30 2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 8月  30 2017 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 8月  30 2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 8月  30 2017 CentOS-Vault.repo

[root@localhost yum.repos.d]# rm -rf C*
[root@localhost yum.repos.d]# touch ./yum.repo
[root@localhost yum.repos.d]# vi yum.repo
[centos]                         //仓库类别
name=CentOS             //仓库名称
baseurl=file:///mnt   //访问仓库的方式和路径
gpgcheck=0                  //验证软件包的签名  0为不验证 1为验证
enabled=1                      //启用此软件仓库
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 //验证签名的公钥文件位置 ,这里使用#注释掉了,因为没有开启验证。


[root@li ~]# yum clean all     //清楚仓库缓存
已加载插件:fastestmirror
正在清理软件源: centos other
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@li ~]# yum makecache   //建立新的仓库缓存
已加载插件:fastestmirror
centos                                                   | 3.6 kB     00:00     
other                                                    | 3.6 kB     00:00     
(1/8): centos/group_gz                                     | 156 kB   00:00     
(2/8): centos/filelists_db                                 | 3.1 MB   00:00     
(3/8): centos/other_db                                     | 1.2 MB   00:00     
(4/8): centos/primary_db                                   | 3.1 MB   00:00     
(5/8): other/group_gz                                      | 1.1 kB   00:00     
(6/8): other/filelists_db                                  |  586 B   00:00     
(7/8): other/other_db                                      |  575 B   00:00     
(8/8): other/primary_db                                    | 1.1 kB   00:00     
Determining fastest mirrors
元数据缓存已建立

6. One-click deployment script shell script

If you don't understand the shell script, you can check https://blog.csdn.net/wulimingde/category_10285021.html

Before using the script, confirm whether the CD is connected to the server. Take a virtual machine as an example

#!/bin/bash
mount /dev/cdrom /mnt
echo "/dev/cdrom /mnt iso9660 defaults 0 0" >> /etc/fstab
systemctl stop firewalld
systemctl disable firewalld
sed -i '7s/enforcing/disabled/g' /etc/selinux/config
cd /etc/yum.repos.d
mkdir backup
mv C* backup/
cp backup/CentOS-Base.repo local.repo
echo "[centos]
name=CentOS
baseurl=file:///mnt
gpgcheck=0
enabled=1
#pgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7" > local.repo
yum clean all
yum makecache
init 6

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/wulimingde/article/details/107794363