Day 操作系统基础优化
系统基础优化
-
创建多用户 :
脚本如何创建多用户 ( 格式如下) :
!/bin/bash --- 一般编写脚本的固定格式
for i in {1..10}
do
useradd stu
i(将用户名stu$i输入到用户里)
done
-
命令提示符的颜色改变 ( 只改变命令提示符的颜色)
PS1='[\e[32;1m][\u@\h \W]$ [\e[0m]'
说明 :
[\e[32;1m] : 信息添加颜色开始 ,包括要添加什么颜色 ; ( 32和Nm共同控制要修改的颜色)
[\u@\h \W]$ : 要添加颜色的信息 ;
[\e[0m] : 信息添加颜色结束 .
-
系统的基础优化 :
-
系统 yum 源优化 ;
yum 源仓库 : 汇总保存多个软件包的服务器 ( 如何搭建自己的源仓库)
yum 源 : /etc/yum.repos.d 配置好源文件便于找到指定的 yum 仓库
-
yum 安装软件程序时,可以解决软件安装的依赖性
优化基础 yum ( base ) : curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
-
优化扩展 yum ( epel -- Extra Packages for Enterprise Linux ) :
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
-
安装基础常用的命令 : yum install -y vim tree wget dos2unix nc nmap net-tools sl cowsay bash-completion
命令的作用 :
vim 文本编辑器 vi 的升级版
tree 查看目录的全部信息
wget
nc nmap net-tools 这三个是和网络相关的命令
sl cowsay 这两个命令这是娱乐作用
bash-completion 对一些命令参数进行补全
报错排查 :
-
无法用 yum 正常下载
网路配置不正确 ping www.baidu.com 查看网络配置是否通畅
yum 源是否更新
原有 yum 缓存需要清除 yum clean all 下载索引信息 ( 直接安装索引直接制动更新)
查看软件是否安装 : rpm -qa cowsay
软件安装了那些信息 : rpm -ql cowsay
-
系统安全有关优化 :
-
防火墙优化 :
-
确认主机里有那些服务 :
- netstat -lntup ---查看网络端口号码信息
-
防火墙关闭 :
-
centos 6 :
-
临时关闭 :
/etc/init.d/iptables stop
/etc/init.d/iptables status
-
永久关闭 :
chkconfig iptables off 关 chkconfig iptables on 开
chkconfig --list|grep iptables
chkconfig --list iptables
-
-
centos 7 :
-
临时关闭 :
- systemctl stop firewalld.service 关 systemctl start firewalld.service 开
-
永久关闭 :
systemctl disable firewalld.service
systemctl enable
-
永久开启 :
- firewalld.service(永久开启)
-
-
-
查看状态 :
systemctl status firewalld.service
systemctl is-active firewalld.service --- 检查服务是否临时关闭或开启
systemctl is-enabled firewalld.service --- 检查服务是否永久关闭或开启
-
-
selinux 的关闭 :
-
centos7 / centos 6 ( 通用 ) :
-
临时关闭 :
setenforce 0
getenforce --- 查看selinux状态
Enforcing /1 --- selinux处于开启状态
Permissive /0 --- selinux处于临时关闭
-
永久关闭 :
/etc/selinux/config 查看此文件
selinux 安全策略是限制 root 用户权限的策略一般企业中都会学着关闭
enforcing - SELinux security policy is enforced. ( seliunux开启状态)
permissive - SELinux prints warnings instead of enforcing. ( selinux临时开启状态)
disabled - No SELinux policy is loaded. ( 禁止 selinux 策略加载 )
选择 SELINUX=disabled 永久关闭 selinux 策略加载
-
修改 selinux 策略 :
利用 vi 命令修改查看
用底行命令查看行数 在进行替换 7s#enforcing#disabled#g
sed 命令直接修改 sed -i '7s#enforcing#disabled#g' /etc/selinux/config
-
-
-
-
-
系统字符串编码优化 :
作用 :
避免中文出现乱码 ;
-
部分信息显示中文 ; ( UTF-8 GBK )
-
查看系统字符串编码类型 ( 一般为 UTF-8 )
-
echo @LANG 查看编码类型
centos 6 :
临时调整 : ( export LANG="en_US.UTF8")
-
永久调整 : vim /etc/locale.conf LANG="en_US.GBK" source /etc/locale.conf localectl set-locale LANG="en_US.UTF-8"
设置系统提示信息为中文: localectl set-locale LANG="zh_CN.UTF-8"
-
-
-
系统的时间和时区优化 :
-
查看时间和时区信息 ;
$ timedatectl Local time: 一 2019-07-15 06:47:10 EDT Universal time: 一 2019-07-15 10:47:10 UTC RTC time: 一 2019-07-15 10:47:11 Time zone: America/New_York (EDT, -0400) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: yes Last DST change: DST began at 日 2019-03-10 01:59:59 EST 日 2019-03-10 03:00:00 EDT Next DST change: DST ends (the clock jumps one hour backwards) at 日 2019-11-03 01:59:59 EDT 日 2019-11-03 01:00:00 EST
-
相关解释 及 同步优化时间:
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n201" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Monaco, Consolas, "Andale Mono", "DejaVu Sans Mono", monospace; margin-top: 0px; margin-bottom: 20px; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(54, 59, 64); font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; position: relative !important; padding: 10px 30px; border: 1px solid; width: inherit; color: rgb(184, 191, 198); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">timedatectl set-time 18:49 --- 设置时间信息
timedatectl set-timezone Asia/Shanghai --- 设置时区信息 ******
timedatectl list-timezones --- 显示时区信息
set-local-rtc BOOL --- 设置RTC功能是否开启 BOOL(数据布尔型--0/1 false/true)
RTC是否修改硬件主板时间
set-ntp BOOL --- 设置NTP功能是否开启
会通过网络自动同步时间
手动同步时间方法:
yum install -y ntpdate
ntpdate "ntp1.aliyun.com"
timedatectl命令操作不了:
第一个里程: 安装时间同步软件
yum install -y chrony
systemctl start chronyd
第二个里程: 修改同步方式
timedatectl set-ntp 1
</pre>
-