一、準(zhǔn)備工作
安裝光盤:CentOS-7-x86_64-Everything-1804.iso (大小8.75G)
主機(jī)名:
ip地址:
掩碼:
網(wǎng)關(guān):
DNS地址(可選):
NTP服務(wù)器地址(可選):
root密碼:
管理機(jī)地址:
說(shuō)明:準(zhǔn)備工作非常重要,強(qiáng)烈建議完成后再進(jìn)行安裝;
日常工作中,我經(jīng)常看到不少?gòu)S家工程師為省心,動(dòng)輒就進(jìn)行完整安裝,
這樣做很浪費(fèi)資源,而且會(huì)帶來(lái)很多漏洞, 是不可取的。
二、安裝
1、插入光盤,服務(wù)器配置為光驅(qū)啟動(dòng)
2、選擇 Install CentOS 7 ,按Enter鍵
3、語(yǔ)言選擇簡(jiǎn)體中文(中國(guó))
4、設(shè)置網(wǎng)絡(luò)與主機(jī)名
5、設(shè)置NTP服務(wù)器
6、軟件選擇
左邊選擇:最小安裝
右邊選擇:調(diào)試工具、兼容性程序庫(kù)、開(kāi)發(fā)工具、安全性工具、系統(tǒng)管理工具
7、點(diǎn)開(kāi)始安裝
8、設(shè)置root 密碼
說(shuō)明:整個(gè)安裝過(guò)程大概20分鐘左右
三、查看安裝結(jié)果
# df -m
文件系統(tǒng) 1M-塊 已用 可用 已用% 掛載點(diǎn)
/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
說(shuō)明:因?yàn)榍懊姘惭b時(shí)我使用了自動(dòng)分區(qū)。
“/” 可以理解為windows系統(tǒng)中的系統(tǒng)盤,因?yàn)槭褂昧俗钚“惭b,系統(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
查看服務(wù)
# chkconfig –list
注:該輸出結(jié)果只顯示 SysV 服務(wù),并不包含
原生 systemd 服務(wù)。SysV 配置數(shù)據(jù)
可能被原生 systemd 配置覆蓋。
要列出 systemd 服務(wù),請(qǐng)執(zhí)行 'systemctl list-unit-files'。
查看在具體 target 啟用的服務(wù)請(qǐng)執(zhí)行
'systemctl list-dependencies [target]'。
netconsole 0:關(guān) 1:關(guān) 2:關(guān) 3:關(guān) 4:關(guān) 5:關(guān) 6:關(guān)
network 0:關(guān) 1:關(guān) 2:開(kāi) 3:開(kāi) 4:開(kāi) 5:開(kāi) 6:關(guān)
到日志目錄查看啟動(dòng)過(guò)程是否有異常
#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 寫保護(hù),將以只讀方式掛載
# 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防火墻
說(shuō)明:這只是個(gè)人習(xí)慣,firewalld防火墻只是對(duì)iptables防護(hù)墻進(jìn)行了一層包裝,我個(gè)人還是覺(jué)得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、準(zhǔn)備工作
INPUT
============================================================
服務(wù) |協(xié)議 |源地址 |源端口 |目的地址 |目標(biāo)端口
————————————————————
ssh |tcp | x.x.x.x | | 22
ping |icmp | x.x.x.x | echo-request
NTP |udp | x.x.x.x | 123
OUTPUT
=========================================================
服務(wù) |協(xié)議 |源地址 |源端口 |目的地址 |目標(biāo)端口
———————————————————
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
測(cè)試日志
# logger -p user.debug "teststr"
# cat /var/log/debug
4、根據(jù)準(zhǔn)備工作的內(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í)行以下三條命令之前,請(qǐng)確認(rèn)關(guān)于 ssh 配置是否正確
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# iptables -P FORWARD DROP
#
配置iptables日志,limit 參數(shù)的數(shù)值可以根據(jù)實(shí)際需求進(jìn)行修改
# 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)絡(luò)的問(wèn)題,可以查看日志
# 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后,可能會(huì)導(dǎo)致某些服務(wù)無(wú)法啟動(dòng),比如VSFTP,對(duì)于VSFTP,需要修改/etc/vsftpd/vsftpd.conf文件中的listen和listen_ipv6兩個(gè)選項(xiàng):
listen=YES
listen_ipv6=NO
驗(yàn)證
# cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1
# lsmod |grep ipv6