This article is about centos7 optimal allocation system, inadequate about this article, please point out, grow together, Thanks✌.ʕʘ‿ʘʔ.✌
Will be described in accordance with the following contents 16
Network setup
configuration using the Internet Yum source and EPEL source
install commonly used system tools
to streamline the boot from the start service
optimization ssh service configuration
add a normal user and sudo authorization management
disabled SeLinux
use the Internet time source synchronous system time
timer automatically clean / tmp (temporary directory) and so do not need to file in the directory, the inode are filled to prevent the
lock important files
to adjust the size of the file descriptor
adapt the character set
to remove the system and kernel version before the login screen displays
ping prohibit
kernel parameter optimization
to create a personal working directory
(A) Network Configuration
主要是配置/etc/sysconfig/network-scripts/ifcfg-ens33此文件
输入命令: vi /etc/sysconfig/network-scripts/ifcfg-ens33
许多系统的网卡名称不一样,可以根据实际名称进行更改
可以依照下图进行修改
然后输入:systemctl restart network 重启服务生效
For more information about modifying the configuration of this card can access another article next -> About Linux Series - modify the network configuration
(B) the configuration and use of the Internet Yum source EPEL source
yum source detailed explanation, please visit -> About Linux Series - How to Configure Internet-based Yum source centos7 to construct a depot
切换到/etc/yum.repos.d目录下,会发现已经有了许多的配置文件
CentOS-Base.repo 这个是联网后基础的源文件,访问速度比较慢
CentOS-Debuginfo.repo和内核相关的更新和软件安装的文件
CentOS-Media.repo 这个是使用光盘挂载后调用的文件
CentOS-fasttrack.repo
CentOS-CR.repo
We replace the original source yum yum source for domestic
Such as Netease mirror sites http://mirrors.163.com/.help/centos.html
点击链接,保存下来,然后上传到centos7中,到/etc/yum.repos.d目录下
然后再清除一下缓存,再生成缓存
用yum repolist 查看yum源软件仓库,发现前后是不一样的。
更改yum源完成
Add EPEL source
使用命令:yum -y install epel-release
Then on OK, ✌ |. • ͡˘‿ • ͡˘ | .✌
(c) the installation of common system tools
可根据自己的需要进行下载
yum -y install tree lrzsz lsof sysstat nmap tcpdump wget vim curl telnet lftp iptraf-ng iftop
tree 查看目录树的结构
lrzsz 文件传输
rz 接收文件
sz 发送文件
wget 文件下载
telnet 远程登录
lftp ftp客户端工具
iptraf-ng 和 iftop 网络流量查看工具
等等。。。
(Iv) streamlining the boot from the start Services
可以根据自己的情况进行一些开机优化设置
systemctl is-enabled firewalld.service #查询防火墙是否开机自启动
systemctl is-enabled sshd.service #查询ssh服务是否开机启动
systemctl enable *.service #开机运行某一项服务
systemctl disable *.service #取消开机运行某一项服务
systemctl start *.service #启动某一项服务
systemctl stop *.service #停止某一项服务
systemctl restart *.service #重启某一项服务
systemctl reload *.service #重新加载某一项服务配置文件
systemctl status *.service #查询某一项服务运行状态
systemctl is-active *.service #查询某一项服务是否活动
systemctl --failed #显示所有启动失败的服务
systemctl list-unit-files#查看全部已安装的服务
(五) 优化ssh服务进行相关配置
为了可以安全快速的连接,开心愉快的使用ssh服务,需要对此配置文件进行以下修改
编辑 /etc/ssh/sshd_config
1、更改SSH服务的默认端口号
Port 52201
2、禁止root用户远程登录
PermitRootLogin no
3、关闭DNS解析
UseDNS no
4、关闭GSS认证
GSSAPIAuthentication no
(六)添加普通用户并进行sudo授权管理
可以用非root用户,如果没有,可以创建一个啰
创建用户 -- useradd wxy
添加密码 -- passwd wxy
输入密码 -- (*****)
确认密码 -- (*****)
使用提权工具:sudo
使用sudo为用户进行授权
以指定的用户身份执行相关的指令
授权配置文件
/etc/sudoers
编辑推荐使用visudo(因为有语法检查的嘛)
有时,可能需要加-f 才能使用此命令
visudo -f /etc/sudoers
授权格式
root ALL=(ALL) ALL
授权用户 主机=(以什么用户身份,若未指定,默认为root用户) 命令列表
其实上图中最后一个命令列表ALL可以指定特定命令,这样授权的用户就只有执行这些命令的特权
喃,最后查看一下:会发现可以运行的命令是所有ALL。
(七)禁用SeLinux
SeLinux是Linux基于内核的安全机制
查询当前SeLinux的状态
[root@krystal ~]# getenforce
默认是被强制启用的
enforcing:强制模式,默认此状态
permissive:宽容模式,违反SeLinux的安全策略行为,不被阻止,但会记录到日志中
disabled:关闭模式,SELinux 并没有实际运作
配置文件:/etc/selinux/config
方法一:直接编辑文件
vi /etc/selinux/config
方法二:用sed命令替换
sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/selinux/config
(八)使用互联网的时间源同步系统时间
工具:ntpdate
软件包:ntpdate
yum -y install ntpdate
手动同步 -- ntpdate time1.aliyun.com
自动同步 -- 配合计划任务(crontab)去同步互联网的时间源
每隔90分钟同步一次
方法一:
编辑一下:crontab -e
*/30 */1 * * * /sbin/ntpdate time1.aliyun.com
查看任务计划:crontab -l
方法二:
echo "*/30 */1 * * * /sbin/ntpdate time1.aliyun.com" >> /var/spool/cron/root
到时间时,会自动同步,然后给你发送一封邮件:
会显示这样的内容,显示与时间服务器同步的信息
(九)定时自动清理/tmp(临时目录)等目录中的不需要文件,防止inode节点被占满
找到30天之前创建的文件,然后执行删除,并把正确输出和错误输出都不可见
find /tmp -type f -mtime +30 | xargs rm -rf >/dev/null 2>&1
配合任务计划使用,事半功倍
echo "find /tmp -type f -mtime +30 | xargs rm -rf >/dev/null 2>&1" >> /var/spool/cron/root
(十)锁定重要文件
系统中比较重要的文件
账号文件 /etc/passwd
密码文件 /etc/shadow
组的账号文件 /etc/group
更改文件的特殊属性 chattr
i —锁住文件的节点,文件只能读,不可修改
chattr +i /etc/passwd
查看文件的特殊属性
lsattr /etc/passwd
这里可以做一个小小的实验,往系统里面添加一个用户,会发现是不能添加的
如果想要去除i节点,就是
chattr -i /etc/passwd
(十一)调整文件描述符大小
临时修改
ulimit -SHn 65535
永久修改
配置文件/etc/security/limits.conf
vi /etc/security/limits.conf
格式是这样滴:
* - nofile 65535
用户 软硬限制 文件描述符 数量
(十二)调整字符集
查看支持的语言环境变量
locale -a
显示当前系统的语言环境变量
echo $LANG
语言环境变量配置文件
vi /etc/locale.conf
可以进行修改,根据自己的喜好随意改变语言环境
wc -l 是为了统计一下有多少个支持的语言环境变量,可以不用加上的,会看到每一个语言环境变量
(十三)去除系统及内核版本登录前的屏幕显示
本地系统登录时显示的内容存放文件
/etc/issue
网络登录时显示的内容存放文件
/etc/issue.net
If you want to quickly clear the contents of this inside
> /etc/issue
> /etc/issue.net
When then log back in, system and kernel version, there is no message
(xiv) prohibits ping
Kernel parameter configuration file
/etc/sysctl.conf
In the kernel configuration file to modify the configuration parameters
echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf
It changes take effect
sysctl -p
就会达到不能ping的效果了
(Xv) kernel parameter optimization
add content /etc/sysctl.conf look inside:
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_syncookies = 1 #抵御SYN Flood能力
net.ipv4.tcp_keepalive_time =600
net.ipv4.ip_local_port_range = 32768 60999
net.ipv4.tcp_max_syn_backlog = 8182
net.core.somaxconn = 1024
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_max_orphans = 2000
(Xvi) to create a personal work directory
have use planning, more reasonable, make work more concise, structured, high efficiency
mkdir -p work/{app,doc,note,scripts}
tree -L 1 work/
ok, in general, the first so prepared, after the new content, and we will continue to be added on the inside, to welcome all friends, valuable advice, the next will be to strengthen the improvement and continuous learning, enhance skills, thanks