CentOS系統做爲紅帽系列的一款linux系統,由於其免費、開源,在中小企業中獲得了普遍應用,生產上爲了更好的利用資源,都採用最小系統安裝,由於一個圖形界面都會佔去系統資源的30%到40%,生產上通常都是最經濟原則,不裝圖形界面,軟件也是須要什麼裝什麼,通常經過ssh鏈接或者xshell鏈接便可。本文從如下四個方面給出了CentOS系統的最小化安裝及在線yum源的配置。html
大綱:
1、搭建CnetOS6.5x64最小系統。
2、ip,主機名等的相關配置。
3、本地和在線yum源的配置。
4、快照及克隆。linux
看圖,一步一步來便可shell
硬盤大小20G 足夠用了, 即便後續不夠可,能夠再添加硬盤,作成磁盤陣列也是能夠的。vim
單個磁盤文件比多個文件好些,若是不許備移動,那麼就用單個磁盤文件。centos
2. 啓動虛擬機:安裝最小系統。緩存
這個地方簡單說明一下:若是你在安裝的時候,忘記選擇某些soft repositories ,好比說:「Develop tools」 這個repository忘記安裝了,服務器
或者你後續還想安裝其他的repositories,那麼能夠用yum group list 看一下:網絡
[root@xiaolyu ~]# yum grouplist Loaded plugins: fastestmirror, security Setting up Group Process Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Installed Groups: Base E-mail server Graphical Administration Tools Hardware monitoring utilities Legacy UNIX compatibility Networking Tools Performance Tools Perl Support Security Tools System administration tools Available Groups: Additional Development Backup Client Backup Server CIFS file server Client management tools Compatibility libraries Console internet tools Debugging Tools Desktop Desktop Debugging and Performance Tools Desktop Platform Desktop Platform Development Development tools Dial-up Networking Support Directory Client Directory Server Eclipse Emacs FCoE Storage Client FTP server Fonts General Purpose Desktop Graphics Creation Tools Guest Agents High Availability High Availability Management Identity Management Server Infiniband Support Input Methods Internet Applications Internet Browser Java Platform KDE Desktop Large Systems Performance Legacy X Window System compatibility Load Balancer Mainframe Access Messaging Client Support MySQL Database client MySQL Database server NFS file server Network Infrastructure Server Network Storage Server Network file system client Office Suite and Productivity PHP Support PostgreSQL Database client PostgreSQL Database server Print Server Printing client Remote Desktop Clients Resilient Storage Ruby Support SNMP Support Scalable Filesystems Scientific support Server Platform Server Platform Development Smart card support Storage Availability Tools System Management TeX support Technical Writing TurboGears application framework Virtualization Virtualization Client Virtualization Platform Virtualization Tools Web Server Web Servlet Engine Web-Based Enterprise Management X Window System iSCSI Storage Client Available Language Groups: Afrikaans Support [af] Albanian Support [sq] Amazigh Support [ber] Arabic Support [ar] Armenian Support [hy] Assamese Support [as] Azerbaijani Support [az] Basque Support [eu] Belarusian Support [be] Bengali Support [bn] Bhutanese Support [dz] Brazilian Portuguese Support [pt_BR] Breton Support [br] Bulgarian Support [bg] Catalan Support [ca] Chhattisgarhi Support [hne] Chichewa Support [ny] Chinese Support [zh] Coptic Support [cop] Croatian Support [hr] Czech Support [cs] Danish Support [da] Dutch Support [nl] English (UK) Support [en_GB] Esperanto Support [eo] Estonian Support [et] Ethiopic Support [am] Faroese Support [fo] Fijian Support [fj] Filipino Support [fil] Finnish Support [fi] French Support [fr] Frisian Support [fy] Friulian Support [fur] Gaelic Support [gd] Galician Support [gl] Georgian Support [ka] German Support [de] Greek Support [el] Gujarati Support [gu] Hebrew Support [he] Hiligaynon Support [hil] Hindi Support [hi] Hungarian Support [hu] Icelandic Support [is] Indonesian Support [id] Interlingua Support [ia] Inuktitut Support [iu] Irish Support [ga] Italian Support [it] Japanese Support [ja] Kannada Support [kn] Kashmiri Support [ks] Kashubian Support [csb] Kazakh Support [kk] Khmer Support [km] Kinyarwanda Support [rw] Konkani Support [kok] Korean Support [ko] Kurdish Support [ku] Lao Support [lo] Latin Support [la] Latvian Support [lv] Lithuanian Support [lt] Low Saxon Support [nds] Luxembourgish Support [lb] Macedonian Support [mk] Maithili Support [mai] Malagasy Support [mg] Malay Support [ms] Malayalam Support [ml] Maltese Support [mt] Manx Support [gv] Maori Support [mi] Marathi Support [mr] Mongolian Support [mn] Myanmar (Burmese) Support [my] Nepali Support [ne] Northern Sotho Support [nso] Norwegian Support [nb] Occitan Support [oc] Oriya Support [or] Persian Support [fa] Polish Support [pl] Portuguese Support [pt] Punjabi Support [pa] Romanian Support [ro] Russian Support [ru] Sanskrit Support [sa] Sardinian Support [sc] Serbian Support [sr] Sindhi Support [sd] Sinhala Support [si] Slovak Support [sk] Slovenian Support [sl] Somali Support [so] Southern Ndebele Support [nr] Southern Sotho Support [st] Spanish Support [es] Swahili Support [sw] Swati Support [ss] Swedish Support [sv] Tagalog Support [tl] Tajik Support [tg] Tamil Support [ta] Telugu Support [te] Tetum Support [tet] Thai Support [th] Tibetan Support [bo] Tsonga Support [ts] Tswana Support [tn] Turkish Support [tr] Turkmen Support [tk] Ukrainian Support [uk] Upper Sorbian Support [hsb] Urdu Support [ur] Uzbek Support [uz] Venda Support [ve] Vietnamese Support [vi] Walloon Support [wa] Welsh Support [cy] Xhosa Support [xh] Zulu Support [zu] Done
找到你但願裝的軟件組,好比:「Develop tools」, yum groupinstall "Develop tools".app
若是不想用這個軟件組了,能夠yum groupremove "Develop tools";ssh
固然了,若是yum源都沒有,那麼一切都白搭,因此後續會講到yum源的配置。
正在安裝:
1. 先設置ip,方便進行xshell的鏈接和後續的在線yum源的安裝。
這裏採用橋接模式:
在vmware上【edit】-> 【virtual network edit】按下圖設置便可。
在我新裝的虛擬機上右鍵【setting】按下圖設置便可。
修改ip地址的配置文件。 vi /etc/sysconfig/network-scripts/ifcfg-eth0
而後重啓服務: service network restart
看一下本機地址:ifconfig
看一下:宿主機的ip地址:
而後ping 一下宿主機的ip地址和百度的網址測試一下內外網是否相通:
ping 192.168.31.160
ping www.baidu.com
由於內外網已經通了,能夠鏈接xshell了,後續的操做便在xshell中進行:
2. 清空iptables
1)iptables -F 清空iptables的相關配置,而後保存該配置文件。咱們能夠man iptables查看iptales的相關命令。這裏不展開。
2)直接關閉iptables 的開機自啓動。
咱們知道rhel6只要是服務,均可以經過chkconfig service-name off 來關閉開機自啓動。
iptables做爲可執行文件,在/etc/init.d的目錄下,固然能夠啦。通常在該目錄下都是服務,而不是通常的應用程序。
chkconfig iptables off
2. 關閉selinux服務。
1)查看selinux服務:
2)關閉selinux。修改配置文件.
vi /etc/sysconfig/selinux
檢驗是selinux是否被關閉,須要重啓系統:reboot。
若是隻是臨時關閉selinux ,能夠執行命令setenforce 0.
reboot 以後是這個樣子:
3. 主機名的修改以及與ip之間映射配置文件說明
#hostname xxx 命令能夠臨時修改機器名,但機器從新啓動以後就會恢復原來的值。
#hostname 查看主機名
#hostname -i 查看本機器名對應的ip地址
vim /etc/hosts 這個文件,就是咱們一般配置主機名,和主機名與ip之間映射的地方。
通常狀況下hosts的內容關於主機名(hostname)的定義,每行爲一個主機,每行由三部份組成,每一個部份由空格隔開。
下面是個人配置文件:
把這上面這個配置文件的內容分別寫入每臺機器的/etc/hosts內容中,這樣這兩臺局域網的機器就能夠經過hostname來訪問了。後面的服務ssh 遠程登陸就用到了主機名和ip地址的映射。
hostname -i 查看本機主機名和ip地址的對應關係。
固然每行也能夠是兩部份,就是主機IP地址和主機名;例如 192.168.31.76 xiaolyu76
127.0.0.1 是迴環地址,好比咱們不想讓局域網的其它機器看到咱們測試的網絡程序,就能夠用迴環地址來測試。
爲何須要定義ip與主機名的映射呢?
其實理解也簡單,好比咱們有三臺主機,每臺作不一樣的事,一臺作MAIL服務器,一臺作FTP服務器,一臺作SMB服務器,因此咱們就能夠這樣來設計hostname;
修改主機名,修改爲你喜歡的主機名。
vi /etc/sysconfig/network
若是想臨時修改一下主機名,能夠這樣:hostname host-name
redhat系列的linux,包含fedora和centos,安裝軟件,最經常使用的無外乎:yum安裝和rpm安裝。
yum軟件安裝,由於不須要依賴包,以及沒必要指出具體的軟件版本,安裝起來極爲方便,所以獲得了普遍的應用。
1. 本地yum源的配置:
由於本地的yum源,就是咱們的iso鏡像系統中的軟件包,所以,須要先掛在ISO鏡像文件,也即:/dev/sr0。
配置本地yum源:
說明:yum源的文件名以repo爲後綴,這是linux中爲數很少的區分後綴名的例子。
配置本地yum源後,須要先清空yun 緩存: yum clean all
而後生成yum列表: yum list
來咱們來試試,用yum安裝一下vim : yum install -y vim // -y 取消交互式安裝,不用提示。
2. 在線yum源的配置:
centos是不須要註冊的,因此能夠獲取在線yum源,固然了,rhel6也能夠經過獲取centos的在線yun源來配置本身的yum源。
爲了便於資料保存,這裏給出了CentOS5,6,7的在線yum源的配置方法。
配置網絡yum源
阿里雲鏡像源站點(http://mirrors.aliyun.com/)。
centos鏡像參考:http://mirrors.aliyun.com/help/centos
網易163開源鏡像網站:(http://mirrors.163.com/)
CentOS鏡像參考:http://mirrors.163.com/.help/centos.html
中科大開源鏡像網站:http://centos.ustc.edu.cn/
搜狐的Linux安裝鏡像源:http://mirrors.sohu.com/
北京首都在線科技:http://mirrors.yun-idc.com/
上面的幾個國內的開源鏡像網站,通常前兩個就能夠了,固然了,最好的方法是不一樣的linux虛擬機配置不一樣的在線yum源,經過比較最終選擇本身最滿意的yum源。
操做徹底同樣。
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生成緩存。
rhel 網絡yum源的配置:
RHEL系統配置:
yum clean all
yum list
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
sed -i 's/$releasever/6.7/g' /etc/yum.repos.d/CentOS-Base.repo
yum clean all
yum list
3. 擴展yum源:epel源的配置:
配置epel源:
配置參考:http://mirrors.aliyun.com/help/epel
Epel
一、備份(若有配置其餘epel源)
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
二、下載新repo 到/etc/yum.repos.d/
epel(RHEL 7)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
epel(RHEL 6)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
epel(RHEL 5)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo
當配置在線yum源成功後,進行yum clean all以後,用yum makecache生成yum緩存時,報以下錯誤:
[root@xiaolyu11 network-scripts]# yum makecache Loaded plugins: fastestmirror, security Determining fastest mirrors * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: (28, 'Connection time-out') Trying other mirror. http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: (28, 'connect() timed out!') Trying other mirror. Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again [root@xiaolyu11 network-scripts]#
解決方法:
1. 修改DNS。添加輔助dns。
[root@xiaolyu11 network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.31.11 NETMASK=255.255.255.0 GETWAY=192.168.31.1 DNS1=8.8.8.8 DNS2=8.8.4.4
也就是ifcfg-eth0末尾添加兩行DNS配置,若是原來有8.8.8.8,那麼也必定要加上8.8.4.4,這兩個地址是google提供的免費DNS服務器的IP地址。
2. 重啓network 服務
[root@xiaolyu11 network-scripts]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining if ip address 192.168.31.11 is already in use for device eth0... [ OK ]
該警告通常是因爲網卡解析arp協議致使的,可在網卡的配置文件中加入ARPCHECK=NO參數來屏蔽該檢查
[root@xiaolyu11 network-scripts]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.31.11 NETMASK=255.255.255.0 GETWAY=192.168.31.1 DNS1=8.8.8.8 DNS2=8.8.4.4 ARPCHECK=no
網卡配置文件末尾添加:ARPCHECK=no
再次重啓網絡服務:
3. yum makecache,成功:
[root@xiaolyu11 network-scripts]# yum makecache Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.7 kB 00:00 base/group_gz | 226 kB 00:00 base/filelists_db | 6.4 MB 00:06 base/primary_db | 4.7 MB 00:04
若是在配置在線yum源的過程當中,也出現關於鏡像地址問題,尤爲是宿主機和虛擬機能夠通訊,虛擬機又能夠ping www.baidu.com一般的狀況下,
請按照上面的方面進行解決。
說明快照和克隆,必須在虛擬機中,不能在xshell中進行。
1. 快照:
快照比較簡單,這裏不詳細描述。
2. 克隆:
首先說明:要克隆一個虛擬機,必須是在虛擬機關機的狀況下才能夠克隆,因此克隆一個虛擬機以前,應該先將該虛擬機關機。
在VMware中選擇->【VM】->【Manage】->【clone】:
進入以下界面:
克隆完成後,須要作的相關工做:
1)開機運行虛擬機,vim /etc/sysconfig/network-scripts/ifcfg-eth0
刪掉mac地址和uuid,否則的話和我原來的機器如出一轍,這個克隆機仍是不能用。下次重啓的時候會自動生成新的mac地址和uuid。
若是有ip地址,ip地址也要修改。
我這裏暫時尚未作集羣,因此主機名,這裏就不修改了。修改方法見上面。
原配置文件:
修改後的配置文件:
2)刪掉網卡。
rm-rf /etc/udev/rules.d/70-persistent-net.rules
重啓系統:reboot
有一點:我也很奇怪:就是爲何配置文件中沒有mac地址和uuid呢?
vim /etc/sysconfig/network-scripts/ifcfg-eth0