day12
A.系統(tǒng)基礎(chǔ)優(yōu)化
B.系統(tǒng)知識階段會回顧
1. 腳本如何創(chuàng)建多個用戶
井!/bin/bash
for i in {1..10}
do
useradd stui;
echo 123456|passwd --stdin stu$i
2. 設(shè)置命令提示符的顏色
井PS1='[\e[36;1m][\u@\h \W]$ [\e[0m]'
永久設(shè)置:vi /etc/profile 添加 #PS1='[\e[36;1m][\u@\h \W]$ [\e[0m]'
3.系統(tǒng)基礎(chǔ)優(yōu)化部分
1)系統(tǒng)yum源優(yōu)化
yum倉庫:匯總保存多個軟件包的服務(wù)器 ??如何搭建yum倉庫??
yum源:/etc/yum.repos.d 配置好yum源文件,便于找到指定的yum的倉庫
yum可以解決軟件的依賴
優(yōu)化基礎(chǔ):yum(base)
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
**優(yōu)化擴展**yum(epel -- Extra Packages for Enterprise Linux)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 將前面命令改為curl -o
**yum install -y vim tree wget dos2unix nc nmap net-tools sl cowsay bash-completion**簡單下載軟件包
wget ---下載文件的工具
vim ---編輯文本 vi升級版
tree ---查看目錄結(jié)構(gòu)樹
dos2unix ---批量轉(zhuǎn)換腳本
nc ---和網(wǎng)絡(luò)有關(guān)
namp ---和網(wǎng)絡(luò)有關(guān)
net-tools ---和網(wǎng)絡(luò)有關(guān)
cowsay sl ---搞笑軟件包
bash-completion ---對一些命令參數(shù)進行補全
一:報錯先看網(wǎng)絡(luò)配置 ping www.baidu.com 查看外網(wǎng)是否可以通
二:yum源更新 PS:上面的命令網(wǎng)址
三:嘗試其他鏡像時:清除yum緩存 yum clean all
重新下載索引清單
查看軟件是否安裝:
rpm -qa cowsay
查看軟件都安裝哪些信息:
rpm -ql cowsay
4.系統(tǒng)安全有關(guān)的優(yōu)化
防護墻優(yōu)化: 關(guān)閉
確認一個主機里面有哪些服務(wù)
netstat -lntup --- 查看網(wǎng)絡(luò)服務(wù)端口號碼信息
centos6
臨時關(guān)閉:
/etc/init.d/iptables stop
/etc/init.d/iptables status
永久關(guān)閉:
chkconfig iptables off chkconfig iptables on
chkconfig --list|grep iptables
chkconfig --list iptables
centos7
臨時關(guān)閉:
systemctl stop firewalld.service systemctl start firewalld.service (臨時開啟)
永久關(guān)閉:
systemctl disable firewalld.service systemctl enable firewalld.service(永久開啟)
查看狀態(tài):
systemctl status firewalld.service
systemctl is-active firewalld.service --- 檢查服務(wù)是否臨時關(guān)閉或開啟
systemctl is-enabled firewalld.service --- 檢查服務(wù)是否永久關(guān)閉或開啟
5.selinux: 企業(yè)中都會關(guān)閉(安全程序和root(皇帝)權(quán)限有關(guān)) --- 關(guān)閉
centos7:
臨時關(guān)閉:
setenforce 0
getenforce --- 查看selinux狀態(tài)
Enforcing /1 --- selinux處于開啟狀態(tài)
Permissive /0 --- selinux處于臨時關(guān)閉
永久關(guān)閉:
/etc/selinux/config
# enforcing - SELinux security policy is enforced.
selinux安全策略是開啟狀態(tài)
# permissive - SELinux prints warnings instead of enforcing.
selinux顯示警告信息代替開啟狀態(tài) == 臨時關(guān)閉
# disabled - No SELinux policy is loaded.
禁止selinux策略加載
SELINUX=disabled
修改文件信息:
方法一: vi
方法二: 替換 :7s#enforcing#disabled#g
方法三: sed sed -i '7s#enforcing#disabled#g' /etc/selinux/config
6.附加系統(tǒng)快捷方式
tab --- 命令補全功能
ctrl+l clear --- 清屏操作
ctrl+c --- 取消或中斷命令的執(zhí)行
ctrl+d --- 快速推出當前系統(tǒng)登錄狀態(tài)
方向鍵 ↑ ↓ --- 調(diào)取曾經(jīng)輸入過的歷史命令
ctrl+方向鍵 ← → --- 按照一個單詞,快速左右移動光標
ctrl+w --- 將光標所在位置前面的一個字符串進行剪切(刪除)
ctrl+y --- 粘貼剪切的內(nèi)容
crtl+a --- 將光標移動到命令行頭部
ctrl+e --- 將光標移動到命令行尾部
ctrl+u --- 刪除光標以前所有的內(nèi)容(實質(zhì)是剪切)
ctrl+k --- 刪除光標以后所有的內(nèi)容(實質(zhì)是剪切)
ctrl+s (suo) --- 使xshell進入鎖定狀態(tài) (這個鎖定狀態(tài)不能替代屏幕鎖屏)
ctrl+q (quit) --- 退出xshell鎖定狀態(tài)
7.系統(tǒng)字符編碼優(yōu)化
作用:
1)避免中文出現(xiàn)亂碼
2)部分信息顯示中文
字符編碼是什么:
王永民發(fā)明了五筆輸入法
UTF-8
gbk
查看系統(tǒng)字符編碼:
echo $LANG
en_US.UTF-8
修改字符編碼:
centos6
臨時調(diào)整:
export LANG="en_US.UTF-8"
永久調(diào)整:
vim /etc/sysconfig/i18n
LANG="en_US.GBK"
centos7:
臨時調(diào)整:
export LANG="en_US.UTF-8"
永久調(diào)整:
vim /etc/locale.conf
LANG="en_US.GBK"
source /etc/locale.conf
localectl set-locale LANG="en_US.UTF-8"
設(shè)置系統(tǒng)提示信息為中文:
localectl set-locale LANG="zh_CN.UTF-8
8.系統(tǒng)時間和時區(qū)優(yōu)化
查看時間和時區(qū)信息:
$ 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
timedatectl set-time 18:49 --- 設(shè)置時間信息
timedatectl set-timezone Asia/Shanghai --- 設(shè)置時區(qū)信息 ******
timedatectl list-timezones --- 顯示時區(qū)信息
set-local-rtc BOOL --- 設(shè)置RTC功能是否開啟 BOOL(數(shù)據(jù)布爾型--0/1 false/true)
RTC是否修改硬件主板時間
set-ntp BOOL --- 設(shè)置NTP功能是否開啟
會通過網(wǎng)絡(luò)自動同步時間
手動同步時間方法:
yum install -y ntpdate
ntpdate "ntp1.aliyun.com"
timedatectl命令操作不了:
第一個里程: 安裝時間同步軟件
yum install -y chrony
systemctl start chronyd
第二個里程: 修改同步方式
timedatectl set-ntp 1