centos最小化安裝后,需要進行一些配置如防火墻selinux,更換yum源,安裝必備軟件包等,具體如下:
一、關閉centos7防火墻,安裝之前的防火墻
停止 Firewall
? systemctl stop firewalld
關閉firewall自動啟動
? systemctl disable firewalld.service
安裝Iptables防火墻
? yum install -y iptables-services
修改iptables配置文件,開放以下端口 (默認開啟了22端口,以便putty等軟件的連接,實例開啟80端口和3306端口,以便后期lamp環境使用,注:80 為Apache默認端口,3306為MySQL的默認端口)
vi /etc/sysconfig/iptables
#添加下面三句話到默認的22端口這條規則的下面
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
修改后的iptables配置文件:
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
重啟iptables
systemctl restart iptables.service
添加iptables開機自啟項
systemctl enable iptables.service
二、關閉selinux
編輯SELINUX配置文件
vi /etc/selinux/config
#注釋掉下面兩行
#SELINUX=enforcing
#SELINUXTYPE=targeted
#增加一行
SELINUX=disabled
保存,關閉
setenforce 0
使設置啟用,在這里最好重啟一下系統,也可以稍后重啟
三、更換yum源
CentOS自帶的國外源有時候會很慢,我們替換成國內的阿里源,也有很多比如163源都很好,國內很多人用,但這里我們就用阿里源做個示例,想用其他源的同學可以去百度一下。
#先進入源的目錄
cd /etc/yum.repo.d
#備份一下官方源
mv CentOS-Base.repo CentOS-Base.repo.bak
#將阿里源文件下載下來
wget -O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo
注意:這一步可能應為本機無wget軟件不能成功,需要先下載,再上傳到相關目錄。
#重建源數據緩存
yum makecache
ok,換源完成
四、相關包的安裝
1.安裝centos7 Base組件包
? yum groupinstall base -y
2.安裝gcc-c++
yum -y install gcc gcc-c++
3.安裝net-tools
? yum install net-tools -y
4.安裝wget
?yum -y install wget
5.centos7沒有killall命令,要先安裝
? yum install psmisc -y
6.安裝vim
? yum install vim -y
7.更新系統
? yum update -y