Linux环境初始优化

前提:先装好系统,可以连接公网。

====================================================================

关闭防火墙和SELinux

systemctl stop firewalld

systemctl disable firewalld

systemctl status firewalld

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

setenforce 0 //先临时关闭selinux

getenforce

====================================================================

配置yum,因为系统默认yum下载软件的时候是从随机地址下载,速度都很慢,有时还无法建立链接下载超时失败等;

配置yum源,从国内下载,可以大大提高我们的使用体验。(这里选择阿里云,CentOS 7 版本,其他版本参考https://developer.aliyun.com/mirror/)

第一步:先备份

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

第二步:下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/(还有epel源)

# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo //选项-O:下载改名,存到目录里

清缓存:

yum clean all

yum repolist //查看源

接下来就可以用yum安装常用工具了:

# yum -y install tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bind-utils nethogs expect sl cowsay

注:最后两个是娱乐命令,执行完命令可以运行一下,看是否正常安装。

# cowsay hello

# sl

====================================================================

优化SSH连接速度(有时个连接半天一直卡着不动)

sed -i '/^GSSAPIAuthentication/s@^@#@g' /etc/ssh/sshd_config

cat  >>/etc/ssh/sshd_config << EOF

UseDNS no #相当于网络命令的-n选项.

GSSAPIAuthentication no #关闭GSS认证.

EOF

#重新启动

systemctl restart sshd

#检查

egrep '^(GSSAPIAuthentication|UseDNS)'  /etc/ssh/sshd_config

====================================================================

修改命令行颜色

# echo  "export PS1='[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]\[\e[31;1m\] \w\[\e[0m\]]\# '" >> /etc/profile

# source /etc/profile //更新,使之当前生效

====================================================================

修改主机名

hostnamectl set-hostname 新主机名 //这种方法永久生效

例:# hostnamectl set-hostname lianxi.test.cn

hostname 新主机名 //这种方法临时生效,重启无效

--------------------------------------------------

对于老系统(如CentOS 6)

先通过命令行临时修改生效:hostname 新主机名

再修改文件永久生效:/etc/hostname

====================================================================

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容