新建LINUX的基本配置流程
主机名称
vim /etc/hostname
IP配置
vim /etc/sysconfig/network-scripts/ifcfg-xxx
DNS配置
vim /etc/resolv.conf
nameserver DNS_IP
本地DNS解析
vim /etc/hosts
防火墙
vim /etc/selinux/config
临时生效 setenforce 0
iptables -F
systemctl stop firewalld
systemctl disable firewalld
systemctl restart network OR /etc/init.d/network restart
修改启动配置
rm -rf /etc/systemd/system/default.target
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
yum
repo位置
/etc/yum.repos.d
安装yum 加速插件
yum install yum-plugin-fastestmirror
加速插件的配置文件
/etc/yum/pluginconf.d/fastestmirror.conf
yum镜像的速度测试记录文件
/var/cache/yum/timedhosts.txt
添加yum源(epel)
yum -y install epel-release.noarch
常用的yum源
epel源:
https://fedoraproject.org/wiki/EPEL
repoforge源:
http://repoforge.org/use/
wget http://repository.it4i.cz/mirrors/repoforge/redhat/el7/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
rpm -ivh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpmphp和mysql源:
https://webtatic.com
清理yum缓存
yum clean all
生成新的缓存
yum makecache
SSH 优化
vim /etc/ssh/sshd_config
修改默认ssh端口:Port 22 # 修改了默认端口为什么连不上 ? 要关闭防火墙
不适用DNS反查,提速:UseDNS no
关闭GSSAPI验证,提速:GSSAPIAuthentication no
禁止root账号从远程登陆:PermitRootLogin no
系统升级
全部升级:yum update
只升级内核: yum update kernel
只升级某个组件:例如: yum update glibc
升级openssl :yum update openssl
NTP同步 - 自动更新服务器时间
让服务器来同步阿里云的NTP时间服务器,把该命令加入到crontab 中来运行
/usr/sbin/ntpdate ntp1.aliyun.com >> /var/log/ntp.log 2>&1; /sbin/hwclock -w
重要文件lock:(解锁 -i)
chattr +i /etc/sudoers
chattr +i /etc/shadow
chattr +i /etc/passwd
chattr +i /etc/grub.conf
查看文件是否加锁的命令
lsattr 文件
系统资源参数优化
查看当前系统资源配置情况 ulimit -a
/etc/security/limits.conf
/etc/security/limits.d/90-nproc.conf(centos6.x)
/etc/security/limits.d/20-nproc.conf(centos7.x)
* soft nproc 20480
* hard nproc 20480
* soft nofile 655360
* hard nofile 655360
* soft memlock unlimited
* hard memlock unlimited
禁止ping操作
echo “1”> /proc/sys/net/ipv4/icmp_echo_ignore_all
设定tcp_wrappers防火墙
/etc/hosts.allow
/etc/hosts/deny
例如 allow里写:sshd:192.168.1.1;
deny里写sshd:All;只允许这个机器sshd访问该本机
有用的组件
yum install lrzsz
常用的镜像站点
比较重要的目录或者文件
/etc/hosts.allow
/etc/hosts.deny
/etc/profile #全局环境变量设置
例子:用sh文件来覆盖文件内容
转载于:https://blog.51cto.com/snowlai/2309829