Centos7 最小安装

Centos7 最小安装

1.ifconfig

yum install net-tools [它提供 ifconfig 工具,如果你不习惯 ip 命令,还可以使用它]

ifconfig

2.设置服务器的主机名称

hostnamectl set-hostname mini

echo $HOSTNAME [检查主机名]

​ [root@mini ~]# echo $HOSTNAME
​ mini

3.更新或升级最小化安装的 CentOS

yum update -y

4.关闭SELINUX

sestatus [查看selinux状态]

vi /etc/selinux/config

​ SELINUX=disabled
重启生效

5.设置静态IP地址

vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

​ BOOTPROTO=”static”
​ IPADDR=”192.168.1.101″
​ NETMASK=”255.255.255.0″
​ NM_CONTROLLED=”no”
​ ONBOOT=”yes”

“NM_CONTROLLED=no”表示该接口将通过该配置文件进行设置,而不是通过网络管理器进行管理。“ONBOOT=yes”告诉我们,系统将在启动时开启该接口

​ 重启网络服务

systemctl restart network.service

​ 验证接口是否配置正确

ip add

​ 因为我的DNS没有设置所以导致了ping外网ping不通

vi /etc/resolv.conf

​ search localdomain
​ nameserver 8.8.8.8
​ nameserver 114.114.114.114

service network restart

ping -c 3 www.baidu.com[测试]

6.修改ssh端口

​ 修改端口

vi /etc/ssh/sshd_config

​ 修改去掉port前面注释,修改port值为21622

​ 使用密钥登陆

mkdir ~/.ssh

chmod 755 ~/.ssh

vi ~/.ssh/authorized_keys

chmod 600 ~/.ssh/authorized_keys

vi /etc/ssh/sshd_config

​ RSAAuthentication yes

​ PubkeyAuthentication yes

​ AuthorizedKeysFile

​ .ssh/authorized_keys

​ 禁止密码登陆

vi /etc/ssh/sshd_config

​ PasswordAuthentication no

​ 重启ssh

service sshd restart

6.安装iptables

​ 首先要停止 firewalld 服务

systemctl stop firewalld.service

​ 禁止 firewalld 服务在系统启动的时候自动启动

systemctl disable firewalld.server

​ 安装iptables 包

yum install iptables-services -y

​ 设置iptables 防火墙服务开机自动启动

systemctl enable iptables

​ 修改iptables配置

​ 查看状态

service iptables status

​ 查看规则

iptables -L -n

​ 清除默认规则

iptables -F

iptables -X

iptables -Z

建立新的规则

​ 允许本地回环 127.0.0.1

iptables -A INPUT -i lo -p all -j ACCEPT

​ 允许已经建立的所有连接

iptables -A INPUT -p all -m state --state ESTABLISHED,RELATED -j ACCEPT

​ 允许内网的所有连接

iptables -A INPUT -s 10.0.0.0/8 -j ACCEPT

​ 允许所有向外发起的连接

iptables -A OUTPUT -j ACCEPT

​ 拒绝 ping 可选

iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j REJECT

​ 允许 SSH 服务端口(一定要打开,不然就不能ssh了)

iptables -A INPUT -p tcp --dport 21622 -j ACCEPT

​ 允许 Web 服务端口

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

​ 允许 https 服务端口

iptables -A INPUT -p tcp --dport 443 -j ACCEPT

​ 允许返回数据给所有ip所有端口 允许所有本机向外的访问

iptables -A OUTPUT -j ACCEPT

​ 除上面允许的规则,抛弃所有INPUT请求 (注意:如果22端口未加入允许规则,SSH链接会直接断开。)

iptables -P INPUT DROP

​ 除上面允许的规则,抛弃所有FORWARD请求

iptables -P FORWARD DROP

​ 除上面允许的规则,抛弃所有OUTPUT请求

iptables -P OUTPUT DROP

​ 保存(ArchLinux系统下的路径可能和其他系统下的路径不同)

sudo service iptables save

​ 重新启动

sudo service iptables restart

​ 列出规则,供查看

iptables -L -n

7.更新yum源

​ 安装wget

yum install wget -y

​ 备份一下源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

​ 转到源目录,按照自己的版本下载源

cd /etc/yum.repos.d/

wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

​ 运行以下命令生成缓存:

yum clean all

yum makecache

8.安装 GCC (GNU 编译器集)

yum install gcc -y

gcc --version

[root@mini yum.repos.d]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright © 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。

9.安装 7-zip 工具(压缩和解压所有已知类型文件的工具)

yum install p7zip -y

Share