展会信息港展会大全

CentOS 6.4 使用总汇
来源:互联网   发布日期:2015-08-21 15:19:52   浏览:2039次  

导读: 大纲 一、安装 二、启动网卡 三、修改主机名 (web.test.com) 四、修改 DNS (8.8.8.8) 五、配置 163 yum 源 六、关闭 SElinux 七、关闭防火墙 (ipv4,ipv6) 八、安装 VIM 编辑器 九、安装 MAN 帮助文档 十、安装 LVM 十一、修改默认语言 十二、安装常用工具 ...

大纲

一、安装

二、启动网卡

三、修改主机名 (web.test.com)

四、修改 DNS (8.8.8.8)

五、配置 163 yum 源

六、关闭 SElinux

七、关闭防火墙 (ipv4,ipv6)

八、安装 VIM 编辑器

九、安装 MAN 帮助文档

十、安装 LVM

十一、修改默认语言

十二、安装常用工具

注:全新以最小化包安装了64位的CentOS6.4统,作为本地的Web服务器使用,现记录全过程!

一、安装

安装方法没有什么特别,光盘或镜像等,说明一下硬盘的分区与文件系统的格式!

1. 分区(例:500G硬盘,8G内存)

/boot --- 256M

/ --- 100G

/data --- 剩余所有

swap --- 16G

2. 文件系统类型:从CentOS 6.X 开始支持 ext4,这里我们选择ext4!可能有博友会问为什么得选择ext4呢?有什么好处吗?嘿嘿,下面我就来简单说明一下,ext2、ext3、ext4我们重点说明ext4!

3. 三种文件系统的区别(以下资料来自网络,我只是整理出来与大家分享)

Ext2(也称第二扩展文件系统): 是 GNU/Linux 系统中标准的文件系统,其特点为存取文件的性能极好,对于中小型的文件更显示出优势,这主要得利于其簇快取层的优良设计。其单一文件大小与文件系统本身的容量上限与文件系统本身的簇大小有关,在一般常见的 x86 电脑系统中,簇最大为 4KB, 则单一文件大小上限为 2048GB, 而文件系统的容量上限为 16384GB。但由于目前核心 2.4 所能使用的单一分割区最大只有 2048GB,因此实际上能使用的文件系统容量最多也只有 2048GB。

Ext3(第三扩展文件系统): 顾名思义,它就是 ext2 的下一代,也就是在保有目前 ext2 的格式之下再加上日志功能。

EXT4(第四扩展文件系统):文件系统是Linux系统下的日志文件系统,是ext3文件系统的后继版本,但是Ext4是Linux文件系统的一次革命。在很多方面,Ext4相对于Ext3的进步要远超过Ext3相对于Ext2的进步。Ext3相对于 Ext2的改进主要在于日志方面,但是Ext4相对于Ext3的的改进是更深层次的,是文件系统数据结构方面的优化,是一个高效的、优秀的、可靠的和极具特点的文件系统,并且EXT3可以转为EXT4的。

EXT4和EXT3的特点和区别:

Ext4 可以提供更佳的性能和可靠性,还有更为丰富的功能:

1. 与 Ext3 兼容。 执行若干条命令,就能从 Ext3 在线迁移到 Ext4,而无须重新格式化磁盘或重新安装系统。原有 Ext3 数据结构照样保留,Ext4 作用于新数据,当然,整个文件系统因此也就获得了Ext4 所支持的更大容量。

2. 更大的文件系统和更大的文件。 较之 Ext3 目前所支持的最大 16TB 文件系统和最大 2TB 文件,Ext4 分别支持 1EB(1,048,576TB, 1EB=1024PB, 1PB=1024TB)的文件系统,以及 16TB 的文件。

3. 无限数量的子目录。 Ext3 目前只支持 32,000 个子目录,而 Ext4 支持无限数量的子目录。

4. Extents。 Ext3 采用间接块映射,当操作大文件时,效率极其低下。比如一个 100MB 大小的文件,在 Ext3 中要建立25,600 个数据块(每个数据块大小为 4KB)的映射表。而 Ext4 引入了现代文件系统中流行的 extents 概念,每个 extent 为一组连续的数据块,上述文件则表示为“该文件数据保存在接下来的 25,600 个数据块中”,提高了不少效率。

5. 多块分配。当写入数据到 Ext3 文件系统中时,Ext3 的数据块分配器每次只能分配一个 4KB 的块,写一个 100MB 文件就要调用 25,600次数据块分配器,而 Ext4 的多块分配器“multiblock allocator”(mballoc) 支持一次调用分配多个数据块。

6. 延迟分配。 Ext3 的数据块分配策略是尽快分配,而 Ext4 和其它现代文件操作系统的策略是尽可能地延迟分配,直到文件在 cache 中写完才开始分配数据块并写入磁盘,这样就能优化整个文件的数据块分配,与前两种特性搭配起来可以显著提升性能。

7. 快速 fsck。 以前执行 fsck 第一步就会很慢,因为它要检查所有的 inode,现在 Ext4 给每个组的 inode表中都添加了一份未使用 inode 的列表,今后 fsck Ext4 文件系统就可以跳过它们而只去检查那些在用的 inode 了。

8. 日志校验。 日志是最常用的部分,也极易导致磁盘硬件故障,而从损坏的日志中恢复数据会导致更多的数据损坏。Ext4 的日志校验功能可以很方便地判断日志数据是否损坏,而且它将 Ext3 的两阶段日志机制合并成一个阶段,在增加安全性的同时提高了性能。

9. “无日志”(No Journaling)模式。 日志总归有一些开销,Ext4 允许关闭日志,以便某些有特殊需求的用户可以借此提升性能。

10. 在线碎片整理。 尽管延迟分配、多块分配和 extents 能有效减少文件系统碎片,但碎片还是不可避免会产生。Ext4 支持在线碎片整理,并将提供 e4defrag 工具进行个别文件或整个文件系统的碎片整理。

11. inode 相关特性。 Ext4 支持更大的 inode,较之 Ext3 默认的 inode 大小 128 字节,Ext4 为了在 inode中容纳更多的扩展属性(如纳秒时间戳或 inode 版本),默认 inode 大小为 256 字节。Ext4 还支持快速扩展属性(fastextended attributes)和 inode 保留(inodes reservation)。

12. 持久预分配(Persistent preallocation)。 P2P软件为了保证下载文件有足够的空间存放,常常会预先创建一个与所下载文件大小相同的空文件,以免未来的数小时或数天之内磁盘空间不足导致下载失败。Ext4 在文件系统层面实现了持久预分配并提供相应的 API(libc 中的 posix_fallocate()),比应用软件自己实现更有效率。

13. 默认启用 barrier。 磁盘上配有内部缓存,以便重新调整批量数据的写操作顺序,优化写入性能,因此文件系统必须在日志数据写入磁盘之后才能写commit 记录,若 commit 记录写入在先,而日志有可能损坏,那么就会影响数据完整性。Ext4 默认启用 barrier,只有当barrier 之前的数据全部写入磁盘,才能写 barrier 之后的数据。(可通过 "mount -o barrier=0"命令禁用该特性。)

二、启动网卡

1. 从标题上可以看出,CentOS 6.4网卡默认开机是不启动的,如下图

网卡

网卡配置文件

大家可以看到 ONBOOT=no ,说明开机不是自启动的!下面我们说一下每个选项的具体意义!

1

2

3

4

5

6

7

8

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0 #网卡接口名称

HWADDR=00:0C:29:87:9D:1D #硬件地址(MAC地址)

TYPE=Ethernet #网上类型

UUID=3efbea06-751a-4add-bec7-13db4d19bc0d #网卡唯一标识符

ONBOOT=no #开机是否启动

NM_CONTROLLED=yes #设备eth0是否可以由Network Manager图形管理工具托管

BOOTPROTO=dhcp #IP地址的获取方式

2. 下面我们修改一下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

HWADDR=00:0C:29:87:9D:1D

TYPE=Ethernet

UUID=3efbea06-751a-4add-bec7-13db4d19bc0d

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=dhcp

有朋友肯定是会急着去启动网卡服务了,CentOS 5下不会报错,但是在CentOS6下网络服务重启后,ip配置发生了错误!原来CentOS6下的网卡的主配置文档中,默认下有NM_CONTROLLED=yes这么一行,这意味着网卡eth0得有 NetworkManager托管,这行中的yes|no的开关控制项的修改是即时生效的,你可以改为no保存后,立即可以解决上述问题!下面我们来修改一下!

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

HWADDR=00:0C:29:87:9D:1D

TYPE=Ethernet

UUID=3efbea06-751a-4add-bec7-13db4d19bc0d

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=dhcp

[root@web ~]# service network restart

Shutting down interface eth0: [ OK ]

Shutting down loopback interface: [ OK ]

Bringing up loopback interface: [ OK ]

Bringing up interface eth0:

Determining IP information for eth0... done.

[ OK ]

[root@web ~]#

修改成功下面我们看一下效果:

ifconfig

至此网上启动完成!

3. 克隆虚拟机网卡无法启动问题

用VMware配置好CentOS后,使用复制(克隆)虚拟机功能复制了一台,但启动后用ifconfig查看IP时,一直提示未找到eth0 ,重启网卡服务:service network restart,提示如下错误信息:

激活网卡失败

解决方法:

(1).查看克隆的网卡地址

mac

从图上我们可以到,虚拟机的MAC与配置文件中的MAC不一致,我们修改一下网卡配置文件!

(2). 修改 ifcfg-eth0 中的 HWADDR 跟上面的MAC地址一样

1

2

3

4

5

6

7

8

9

10

11

[root@localhost ~]# !vim

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

DEVICE=eth0

HWADDR=00:0C:29:87:9D:1D

TYPE=Ethernet

UUID=3efbea06-751a-4add-bec7-13db4d19bc0d

ONBOOT=yes

BOOTPROTO=dhcp

(3). 删除 /etc/udev/rules.d/70-persistent-net.rules 并重启即可

[root@localhost ~]# rm –rf /etc/udev/rules.d/70-persistent-net.rules

[root@localhost ~]# reboot

三、修改主机名

1

2

3

4

5

6

7

[root@web ~]# vim /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=web.test.com

[root@web ~]# vim /etc/hosts

127.0.0.1 web web.test.com localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@localhost ~]# reboot

四、修改DNS

1

2

3

4

5

6

[root@web ~]# vim /etc/resolv.conf

; generated by /sbin/dhclient-script

search sh.jjhh.com test.com

nameserver 211.95.1.97 #上海联通DNS

nameserver 8.8.8.8 #google DNS

#说明:nameserver 最多可以设置三个

五、配置 yum 源

1. 查看yum源

CentOS 5.X

1

2

3

4

5

[root@localhost ~]# ls -l /etc/yum.repos.d/

total 16

-rw-r--r-- 1 root root 2245 Apr 26 2010 CentOS-Base.repo

-rw-r--r-- 1 root root 626 Apr 26 2010 CentOS-Media.repo

[root@localhost ~]#

CentOS 6.X

1

2

3

4

5

6

[root@web ~]# ls -l /etc/yum.repos.d/

total 16

-rw-r--r--. 1 root root 1926 Feb 25 16:57 CentOS-Base.repo #是网络源,默认使用

-rw-r--r--. 1 root root 638 Feb 25 16:57 CentOS-Debuginfo.repo #测试文件

-rw-r--r--. 1 root root 630 Feb 25 16:57 CentOS-Media.repo #本地资源

-rw-r--r--. 1 root root 3664 Feb 25 16:57 CentOS-Vault.repo #以前版有yum源,这是由当前版本包废弃,通常不应该被用于生产

2. 配置网易163的yum源

(1). yum安装 wget

1

[root@web ~]# yum install wget

(2). 下载repo文件

下载地址:http://mirrors.163.com/.help/CentOS6-Base-163.repo

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

[root@web ~]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

--2013-06-28 19:21:47-- http://mirrors.163.com/.help/CentOS6-Base-163.repo

Resolving mirrors.163.com... 123.58.173.106

Connecting to mirrors.163.com|123.58.173.106|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 2006 (2.0K) [application/octet-stream]

Saving to: “CentOS6-Base-163.repo”

100%[============================================================================================>] 2,006 --.-K/s in 0.01s

2013-06-28 19:21:51 (137 KB/s) - “CentOS6-Base-163.repo” saved [2006/2006]

[root@web ~]# ll

total 36

-rw-------. 1 root root 970 Jun 20 05:03 anaconda-ks.cfg

-rw-r--r-- 1 root root 2006 Sep 1 2011 CentOS6-Base-163.repo

-rw-r--r--. 1 root root 15709 Jun 20 05:03 install.log

-rw-r--r--. 1 root root 4178 Jun 20 05:01 install.log.syslog

drwxr-xr-x 2 root root 4096 Jun 22 20:30 src

[root@web ~]#

(3). 备份并替换系统的repo文件

1

2

3

4

5

6

7

8

[root@web ~]# cd /etc/yum.repos.d/

[root@web yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak

[root@web yum.repos.d]# ls

CentOS-Base.repo.bak CentOS-Media.repo

[root@web yum.repos.d]# mv /root/CentOS6-Base-163.repo CentOS-Base.repo[root@web yum.repos.d]# ls

CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Vault.repo

CentOS-Base.repo.bak CentOS-Media.repo

[root@web yum.repos.d]#

(4). 执行yum源更新

1

2

3

[root@localhost ~]# yum clean all

[root@localhost ~]# yum makecache

[root@localhost ~]# yum update

六、关闭 SElinux

1. 临时关闭

1

2

3

4

5

6

7

[root@localhost ~]# getenforce

Enforcing

[root@localhost ~]#

[root@localhost ~]# setenforce 0

[root@localhost ~]# getenforce

Permissive

[root@localhost ~]#

2. 完全关闭

1

2

3

4

5

6

7

8

9

10

11

12

13

[root@localhost ~]# vim /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - SELinux is fully disabled.

SELINUX=disabled

# SELINUXTYPE= type of policy in use. Possible values are:

# targeted - Only targeted network daemons are protected.

# strict - Full SELinux protection.

SELINUXTYPE=targeted

~

[root@localhost ~]# reboot

七、关闭防火墙

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

[root@web yum.repos.d]# service iptables stop

iptables: Flushing firewall rules: [ OK ]

iptables: Setting chains to policy ACCEPT: filter [ OK ]

iptables: Unloading modules: [ OK ]

[root@web yum.repos.d]# service ip6tables stop

ip6tables: Flushing firewall rules: [ OK ]

ip6tables: Setting chains to policy ACCEPT: filter [ OK ]

ip6tables: Unloading modules: [ OK ]

[root@web yum.repos.d]# chkconfig iptables off

[root@web yum.repos.d]# chkconfig ip6tables off

[root@web yum.repos.d]# chkconfig ip6tables --list

ip6tables 0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@web yum.repos.d]# chkconfig iptables --list

iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off

[root@web yum.repos.d]#

八、安装 VIM 编辑器

1. 查看

vi

vim'

默认没有安装vim

2. 安装vim

1

[root@web yum.repos.d]# yum install vim*

vim

vim安装

九、安装 MAN 帮助文档

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

[root@web ~]# yum install man*

[root@web ~]# man vim

VIM(1) VIM(1)

NAME

vim - Vi IMproved, a programmers text editor

SYNOPSIS

vim [options] [file ..]

vim [options] -

vim [options] -t tag

vim [options] -q [errorfile]

ex

view

gvim gview evim eview

rvim rview rgvim rgview

DESCRIPTION

Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is

especially useful for editing programs.

There are a lot of enhancements above Vi: multi level undo, multi windows and buffers, syntax highlighting, com-

mand line editing, filename completion, on-line help, visual selection, etc.. See":help vi_diff.txt" for a sum-

mary of the differences between Vim and Vi.

十、安装 LVM

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

[root@web ~]# yum install lvm2

[root@web ~]# man lvm

LVM(8) LVM(8)

NAME

lvm - LVM2 tools

SYNOPSIS

lvm [command | file]

DESCRIPTION

lvm provides the command-line tools for LVM2. A separate manual page describes eachcommand in detail.

If lvm is invoked with no arguments it presents a readline prompt (assuming it was compiled with readline sup-

port). LVM commands may be entered interactively at this prompt with readline facilities including history and

command name and option completion. Refer to readline(3) for details.

If lvm is invoked with argv[0] set to the name of a specific LVM command (forexample by using a hard or soft

link) it acts as that command.

On invocation, lvm requires that only the standard file descriptors stdin, stdout and stderr are available. If

others are found, they get closed and messages are issued warning about the leak.

Where commands take VG or LV names as arguments, the full path name is optional. An LV called "lvol0" in a VG

called "vg0" can be specified as "vg0/lvol0". Where a list of VGs is required but is left empty, a list of all

VGs will be substituted. Where a list of LVs is required but a VG is given, a list of all the LVs in that VG

will be substituted. So lvdisplay vg0 will display all the LVs in "vg0". Tags can also be used - see --addtag

below.

One advantage of using the built-in shell is that configuration information gets cached internally between com-

mands.

A file containing a simple script with one command per line can also be given on thecommand line. The script

can also be executed directly if the first line is #! followed by the absolute path of lvm.

十一、修改默认语言

1

2

3

4

[root@web ~]# vim /etc/sysconfig/i18n

LANG="en_US.UTF-8"

~

[root@web ~]# export LANG=en

十二、安装常用工具

1. 常见压缩工具 zip unzip bzip2

1

[root@localhost ~]# yum -y install unzip zip bzip2 bzip2-devel

2. gcc gcc++编译器

1

[root@localhost ~]# yum install gcc gcc-c++ –y

3. cmake编译器

1

[root@localhost ~]# yum install cmake make –y

4. 图片资源

1

[root@localhost ~]# yum -y install gd libjpeg libjpeg-devel libpng libpng-devel freetype-devel

5. 其它常用资源包工具

1

[root@localhost ~]# yum -y install autoconf bison automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*

到此所有演示全部完成! ^_^ ……

本文出自 “Share your knowledge …” 博客,请务必保留此出处http://freeloda.blog.51cto.com/2033581/1231645

赞助本站

人工智能实验室

相关热词: CentOS 使用 总汇 大纲

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港