RHEL6.5環境的基礎配置
- 配置網絡
- 關閉防火牆
- 關閉selinux
- 配置本地yum源
配置網絡yum源
1. 配置網絡
配置網絡可以有好幾種配置,以下講解用配置文件配置靜態IP地址。
1.1編輯/etc/sysconfig/network-script/ifcfg-eth0文件,內容如下:
# 此配置文件應用到的設備
DEVICE=eth0
# 對應的設備的MAC地址
HWADDR=00:0C:29:68:FE:A3
# 接口類型;常見有的Ethernet, Bridge
TYPE=Ethernet
# 設備的惟一標識
UUID=6a6234fe-231a-4068-805e-583561fb9ae8
# 啓動網卡
ONBOOT=yes
# NM是NetworkManager的簡寫,此網卡是否接受NM控制;建議RHLE6爲“no”
NM_CONTROLLED=no
# 有三種類型:none,static,dhcp
BOOTPROTO=static
# IP地址
IPADDR=192.168.0.75
# 子網掩碼
NETMASK=255.255.255.0
# 默認網關
GATEWAY=192.168.0.1
# DNS服務器IP
DNS1=114.114.114.114
IPV6INIT=no
USERCTL=no
1.2 重啓網絡服務
[root@localhost ~]# 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.0.75 is already in use for device eth0...
[ OK ]
1.3 查看配置是否生效
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:68:FE:A3
inet addr:192.168.0.75 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe68:fea3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2053 errors:0 dropped:0 overruns:0 frame:0
TX packets:1648 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:639687 (624.6 KiB) TX bytes:188127 (183.7 KiB)
1.4 測試網絡是否暢通
[root@localhost ~]# ping -c 3 www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_seq=1 ttl=55 time=55.3 ms
64 bytes from 115.239.210.27: icmp_seq=2 ttl=55 time=58.2 ms
64 bytes from 115.239.210.27: icmp_seq=3 ttl=55 time=78.4 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2080ms
rtt min/avg/max/mdev = 55.396/64.040/78.462/10.268 ms
2. 關閉防火牆
2.1 配置開機自動關閉
[root@localhost ~]# chkconfig iptables off
2.2 臨時關閉防火牆
[root@localhost ~]# service iptables stop
2.3 查看啓動級別開機啓動防火牆狀態
[root@localhost ~]# chkconfig --list iptables
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
上面顯示6個啓動級別都是出於關閉狀態,防火牆關閉成功。
3.關閉selinux
3.1 臨時關閉selinux
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
3.2 開機自動關閉selinux
[root@localhost ~]# sed -i '/SELINUX=/cSELINUX=disabled' /etc/selinux/config
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
SELINUX=disabled
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
3.3重啓系統
[root@localhost ~]# reboot
3.4檢查是否成功關閉selinux
[root@localhost ~]# getenforce
Disabled
以上顯示爲Disabled,所以關閉防火牆成功。
4. 配置本地yum源
4.1 檢查光驅是否正常
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 1G 0 part [SWAP]
└─sda3 8:3 0 4.9G 0 part /
sr0 11:0 1 3.6G 0 rom # 光驅正確啓動
4.2 配置開機自動掛載光驅
[root@localhost ~]# echo '/dev/sr0 /mnt iso9660 defaults 0 0' >> /etc/fstab
4.3 掛載配置/etc/fstab中的設備
[root@localhost ~]# mount -a
mount: block device /dev/sr0 is write-protected, mounting read-only
4.4 配置本地yum 源
4.4.1 刪除默認的yum源配置文件
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
4.4.2 新增本地yum源配置文件
[root@localhost ~]# vim /etc/yum.repos.d/rhel6.local.repo
name=rhel6-source # yum源名稱
baseurl=file:///mnt # yum描述信息
enabled=1 # yum源狀態【0:關閉,1:開啓】
gpgcheck=0 # 不驗證
4.4.3配置網絡yum源【使用的是阿里雲的yum源】
CentOS 5
wget-O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget-O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget-O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo
如果用的是RHEL6 ,需要修改下repo文件:
sed -i's/$releasever/6/g' CentOS-Base.repo
之後運行yummakecache生成緩存
4.4.4 安裝epel源
yum install epel-release –y
4.4.5 清空本地主機yum緩存
[root@localhost ~]# yum clean all
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: base epel extras rhel6-local-source updates
Cleaning up Everything
4.4.6 更新yum源緩存使其配置生效
[root@localhost ~]# yum list
4.4.7 查看已經啓動的yum源
[root@localhost ~]# yum repolist
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id repo name status
base CentOS-6 - Base - mirrors.aliyun.com 6,706
*epel Extra Packages for Enterprise Linux 6 - x86_64 12,365
extras CentOS-6 - Extras - mirrors.aliyun.com 45
rhel6-local-source rhel6-source 3,690
updates CentOS-6 - Updates - mirrors.aliyun.com 426
repolist: 23,232
以上顯示yum已經生效了,配置yum成功。當然啦,你可以不用配置網絡yum源,只需配置本地yum即可,也可以完成後期相關服務搭建。