一、準備工作
安裝光盤:CentOS-7-x86_64-Everything-1804.iso (大小8.75G)
主機名:
ip地址:
掩碼:
網(wǎng)關:
DNS地址(可選):
NTP服務器地址(可選):
root密碼:
管理機地址:
說明:準備工作非常重要,強烈建議完成后再進行安裝;
日常工作中,我經(jīng)??吹讲簧購S家工程師為省心,動輒就進行完整安裝,
這樣做很浪費資源,而且會帶來很多漏洞, 是不可取的。
二、安裝
1、插入光盤,服務器配置為光驅啟動
2、選擇 Install CentOS 7 ,按Enter鍵
3、語言選擇簡體中文(中國)
4、設置網(wǎng)絡與主機名
5、設置NTP服務器
6、軟件選擇
左邊選擇:最小安裝
右邊選擇:調試工具、兼容性程序庫、開發(fā)工具、安全性工具、系統(tǒng)管理工具
7、點開始安裝
8、設置root 密碼
說明:整個安裝過程大概20分鐘左右
三、查看安裝結果
# df -m
文件系統(tǒng) 1M-塊 已用 可用 已用% 掛載點
/dev/mapper/centos-root 51175 1622 49554 4% /
devtmpfs 3900 0 3900 0% /dev
tmpfs 3912 0 3912 0% /dev/shm
tmpfs 3912 9 3903 1% /run
tmpfs 3912 0 3912 0% /sys/fs/cgroup
/dev/sda1 1014 142 873 14% /boot
/dev/mapper/centos-home 42084 33 42052 1% /home
tmpfs 783 0 783 0% /run/user/0
說明:因為前面安裝時我使用了自動分區(qū)。
“/” 可以理解為windows系統(tǒng)中的系統(tǒng)盤,因為使用了最小安裝,系統(tǒng)盤只用掉了1.6G空間
"/home"可以理解為數(shù)據(jù)盤
# uname -a
Linux zabbix 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
查看安裝了那些軟件
# rpm -qa|sort
查看服務
# chkconfig –list
注:該輸出結果只顯示 SysV 服務,并不包含
原生 systemd 服務。SysV 配置數(shù)據(jù)
可能被原生 systemd 配置覆蓋。
要列出 systemd 服務,請執(zhí)行 'systemctl list-unit-files'。
查看在具體 target 啟用的服務請執(zhí)行
'systemctl list-dependencies [target]'。
netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關
network 0:關 1:關 2:開 3:開 4:開 5:開 6:關
到日志目錄查看啟動過程是否有異常
#cd /var/log
#cat boot.log
#cat dmesg
四、配置本地yum
# cd /etc/yum.repos.d/
yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
yum.repos.d]# rm *
rm:是否刪除普通文件 "CentOS-Base.repo"?y
rm:是否刪除普通文件 "CentOS-CR.repo"?y
rm:是否刪除普通文件 "CentOS-Debuginfo.repo"?y
rm:是否刪除普通文件 "CentOS-fasttrack.repo"?y
rm:是否刪除普通文件 "CentOS-Media.repo"?n
rm:是否刪除普通文件 "CentOS-Sources.repo"?y
rm:是否刪除普通文件 "CentOS-Vault.repo"?y
yum.repos.d]# vi CentOS-Media.repo #修改以下兩行
baseurl=file:///media/cdrom/
enabled=1
yum.repos.d]# mount /dev/sr0 /media/cdrom
mount: /dev/sr0 寫保護,將以只讀方式掛載
# yum update
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
c7-media | 3.6 kB 00:00:00
(1/2): c7-media/group_gz | 166 kB 00:00:00
(2/2): c7-media/primary_db | 5.9 MB 00:00:00
No packages marked for update
五、禁用firewalld防火墻,啟用iptables防火墻
說明:這只是個人習慣,firewalld防火墻只是對iptables防護墻進行了一層包裝,我個人還是覺得iptables更為好用
# systemctl stop firewalld
# systemctl disable firewalld
# firewall-cmd –state
not running
# yum -y install iptables-devel iptables-services
# systemctl enable iptables
# systemctl start iptables
六、配置iptables防火墻
1、準備工作
INPUT
============================================================
服務 |協(xié)議 |源地址 |源端口 |目的地址 |目標端口
————————————————————
ssh |tcp | x.x.x.x | | 22
ping |icmp | x.x.x.x | echo-request
NTP |udp | x.x.x.x | 123
OUTPUT
=========================================================
服務 |協(xié)議 |源地址 |源端口 |目的地址 |目標端口
———————————————————
NTP |upd | | | x.x.x.x | 123
ping |icmp |x.x.x.x |echo-reply
ssh |tcp | |22 | x.x.x.x |
2、刪除所有規(guī)則
# iptables -t nat -X
# iptables -t nat -Z
# iptables -t nat -F
# iptables -t raw -F
# iptables -t raw -Z
# iptables -t raw -X
# iptables -t mangle -X
# iptables -t mangle -F
# iptables -t mangle -Z
# iptables -Z
# iptables -F
# iptables -X
# iptables -L -n -v
Chain INPUT (policy ACCEPT 48 packets, 3648 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 26 packets, 2608 bytes)
pkts bytes target prot opt in out source destination
3、配置系統(tǒng)Debug日志
# touch /var/log/debug
# vi /etc/rsyslog.conf
增加一行
*.debug /var/log/debug
# service rsyslog restart
測試日志
# logger -p user.debug "teststr"
# cat /var/log/debug
4、根據(jù)準備工作的內(nèi)容配置iptables
# iptables -A INPUT -p tcp -s x.x.x.x–dport 22 -j ACCEPT
# iptables -A OUTPUT -p tcp -d x.x.x.x –sport 22 -j ACCEPT
# iptables -A INPUT -p udp -s x.x.x.x –sport 123 -j ACCEPT
# iptables -A OUTPUT -p udp -d x.x.x.x –dport 123 -j ACCEPT
# iptables -A OUTPUT -p icmp –icmp-type echo-reply -d x.x.x.x/24 -j ACCEPT
# iptables -A INPUT -p icmp –icmp-type echo-request -s x.x.x.x/24 -j ACCEPT
注意:執(zhí)行以下三條命令之前,請確認關于 ssh 配置是否正確
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# iptables -P FORWARD DROP
#
配置iptables日志,limit 參數(shù)的數(shù)值可以根據(jù)實際需求進行修改
# iptables -A INPUT -m limit –limit 6/minute –limit-burst 5 -j LOG –log-prefix "IPTABLES INPUT:" –log-level debug
# iptables -A OUTPUT -m limit –limit 6/minute –limit-burst 5 -j LOG –log-prefix "IPTABLES OUTPUT:" –log-level debug
# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ 確定 ]
查看配置文件是否保存成功
# cat /etc/sysconfig/iptables
有網(wǎng)絡的問題,可以查看日志
# cat /var/log/debug |grep IPTABLES |tail
禁用IPV6
Step 1: add this rule in /etc/sysctl.conf : net.ipv6.conf.all.disable_ipv6=1
Step 2: add this rule in /etc/sysconfig/network: NETWORKING_IPV6=no
Step 3: add this setting for each nic X (X is the corresponding number for each nic) in /etc/sysconfig/network-scripts/ifcfg-ethX: IPV6INIT=no
Step 4: disable the ip6tables service : chkconfig ip6tables off
Step 5: Reload the sysctl configuration:
# sysctl -p
or
# reboot
注意:禁用IPV6后,可能會導致某些服務無法啟動,比如VSFTP,對于VSFTP,需要修改/etc/vsftpd/vsftpd.conf文件中的listen和listen_ipv6兩個選項:
listen=YES
listen_ipv6=NO
驗證
# cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1
# lsmod |grep ipv6