安装Centos虚拟机

更换CentOS7的下载源为阿里云
1、备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3、之后运行yum makecache生成缓存
http://mirrors.aliyun.com/help/


如何在CentOS 7上修改主机名

在CentOS中,有三种定义的主机名:静态的(static),瞬态的(transient),和灵活的(pretty)。
静态主机名也称为内核主机名,是系统在启动时从/etc/hostname自动初始化的主机名。
瞬态主机名是在系统运行时临时分配的主机名,例如,通过DHCP或mDNS服务器分配。静态主机名和瞬态主机名都遵从作为互联网域名同样的字符限制规则。而另一方面,灵活主机名则允许使用自由形式(包括特殊/空白字符)的主机名,以展示给终端用户(如qqmm)。
在CentOS 7中,有个叫hostnamectl的命令行工具,它允许你查看或修改与主机名相关的配置。

要查看主机名相关的设置:
[root@localhost ~]# hostnamectl
Static hostname: localhost.localdomain
      Icon name: computer-vm
        Chassis: vm
     Machine ID: 21ff9d4ebdd94e949b9fd6cbdb1926c0
        Boot ID: 2a952e91c02841e3ae10de0d16dd3f01
 Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
    CPE OS Name: cpe:/o:centos:centos:7
         Kernel: Linux 3.10.0-327.el7.x86_64
   Architecture: x86-64
[root@localhost ~]# hostnamectl status
Static hostname: localhost.localdomain
      Icon name: computer-vm
        Chassis: vm
     Machine ID: 21ff9d4ebdd94e949b9fd6cbdb1926c0
        Boot ID: 2a952e91c02841e3ae10de0d16dd3f01
 Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
    CPE OS Name: cpe:/o:centos:centos:7
         Kernel: Linux 3.10.0-327.el7.x86_64
   Architecture: x86-64
只查看静态、瞬态或灵活主机名,分别使用--static,--transient或--pretty选项。

[root@localhost ~]# hostnamectl --static
localhost.localdomain
[root@localhost ~]# hostnamectl --transient
localhost.localdomain
[root@localhost ~]# hostnamectl --pretty
要同时修改所有三个主机名:静态、瞬态和灵活主机名:

[root@localhost ~]# hostnamectl set-hostname qqmm
[root@localhost ~]# hostnamectl --pretty
[root@localhost ~]# hostnamectl --static
qqmm
[root@localhost ~]# hostnamectl --transient
qqmm
就像上面展示的那样,在修改静态/瞬态主机名时,任何特殊字符或空白字符会被移除,而提供的参数中的任何大写字母会自动转化为小写。
一旦修改了静态主机名,/etc/hostname 将被自动更新。然而,/etc/hosts 不会更新以保存所做的修改,所以你每次在修改主机名后一定要手动更新/etc/hosts,之后再重启CentOS 7。否则系统再启动时会很慢。

手动更新/etc/hosts
vim /etc/hosts
#127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1  centos7.example.com
#::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
::1        centos7.example.com
重启CentOS 7 之后(reboot -f ),
[root@qqmm ~]# hostname
qqmm
[root@qqmm ~]# hostnamectl
Static hostname: qqmm
     Icon name: computer-vm
       Chassis: vm
    Machine ID: 21ff9d4ebdd94e949b9fd6cbdb1926c0
       Boot ID: 2a952e91c02841e3ae10de0d16dd3f01
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
   CPE OS Name: cpe:/o:centos:centos:7
        Kernel: Linux 3.10.0-327.el7.x86_64
  Architecture: x86-64
如果你只想修改特定的主机名(静态,瞬态或灵活),你可以使用--static,--transient或--pretty选项。例如,要永久修改主机名,你可以修改静态主机名:
[root@localhost ~]# hostnamectl --static set-hostname centos7.example.com
重启CentOS 7 之后(reboot -f ),
[root@localhost ~]# hostnamectl --static
qqmm
[root@localhost ~]# hostnamectl --transient
qqmm
[root@localhost ~]# hostnamectl --pretty
qqmm
[root@localhost ~]# hostname
qqmm
其实,你不必重启机器以激活永久主机名修改。上面的命令会立即修改内核主机名。
注销并重新登入后在命令行提示来观察新的静态主机名

yum upgrade


Swap Size - This is a prerequisite condition to test whether sufficient total swap space is available on the system.
Expected Value
: 7.9062GB (8290304KB)
Actual Value
: 2GB (2097144KB)
Details:
-
PRVF-7573 : Sufficient swap size is not available on node "localhost.local" [Required = 7.9062GB (8290304KB) ; Found = 2GB (2097144KB) –
Cause:  The swap size found does not meet the minimum requirement.  - Action:  Increase swap size to at least meet the minimum swap space requirement.
7.9062 - 2 = 5.9GB (minimum swap need)

1 check what swap size
#swapon –s
Filename                                Type            Size    Used    Priority
/dev/xvda3                              partition       2097144 0       -1
 
2 Create a file that you’ll use for swap with dd command with   as root
dd if=/dev/zero of={/swapfile path} bs={size of swap}  count=1048576
Example:-
[root@localhost]#dd if=/dev/zero of=/home/swapfile bs=6048 count=1048576
Note :- Above command will be create the 6Gb swapfile on /home location as  swapfile
3 Set up a Linux swap area

#mkswap /home/swapfile
4: Enabling the swap file

#swapon /home/swapfile
#swapon –a
5 status of add swap
[root@myrem12c em12cBP1]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/xvda3                              partition       2097144 0       -1
/home/swapfile                          file            6097144 0       -2
6 Update /etc/fstab   (this must to be done )

#vi /etc/fstab
/home/swapfile        none             swap   sw      0 0  
Note  :- Add above line ending with  the file otherwise ones you restart the server swap partition not be mounted to the system

请使用浏览器的分享功能分享到微信等