CentOS 7.5 最小化安装

一、准备工作
  安装光盘:CentOS-7-x86_64-Everything-1804.iso (大小8.75G)
  主机名:
  ip地址:
  掩码:
  网关:
  DNS地址(可选):
  NTP服务器地址(可选):
  root密码:
  管理机地址:
 
  说明:准备工作非常重要,强烈建议完成后再进行安装;
        日常工作中,我经常看到不少厂家工程师为省心,动辄就进行完整安装,
        这样做很浪费资源,而且会带来很多漏洞, 是不可取的。
        
二、安装
  1、插入光盘,服务器配置为光驱启动
  2、选择 Install CentOS 7 ,按Enter键
  3、语言选择简体中文(中国)
  4、设置网络与主机名        
  5、设置NTP服务器
  6、软件选择
       左边选择:最小安装
       右边选择:调试工具、兼容性程序库、开发工具、安全性工具、系统管理工具
  7、点开始安装
  8、设置root 密码
 
  说明:整个安装过程大概20分钟左右
 
三、查看安装结果

# df -m
文件系统                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

说明:因为前面安装时我使用了自动分区。
      “/” 可以理解为windows系统中的系统盘,因为使用了最小安装,系统盘只用掉了1.6G空间
      "/home"可以理解为数据盘

# 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 配置数据
可能被原生 systemd 配置覆盖。

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      '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
   ============================================================
   服务 |协议  |源地址     |源端口        |目的地址   |目标端口
   ------------------------------------------------------------
   ssh   |tcp  | x.x.x.x   |                          | 22
   ping  |icmp | x.x.x.x   | echo-request
   NTP   |udp  | x.x.x.x   | 123
   
   OUTPUT
   =========================================================
   服务 |协议  |源地址     |源端口     |目的地址   |目标端口
   ---------------------------------------------------------
   NTP  |upd   |           |           | x.x.x.x   | 123
   ping |icmp  |x.x.x.x    |echo-reply
   ssh  |tcp   |           |22         | x.x.x.x   |
   
   
   
2、删除所有规则
# 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、配置系统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、根据准备工作的内容配置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

注意:执行以下三条命令之前,请确认关于 ssh 配置是否正确
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# iptables -P FORWARD DROP
#
 
配置iptables日志,limit 参数的数值可以根据实际需求进行修改
# 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
 
有网络的问题,可以查看日志
# 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

猜你喜欢

转载自blog.csdn.net/zjyklwg/article/details/82656043