数据库运维
记录DBA学习成长历程

第4章:Linux系统基础优化

文章目录

1.Linux命令提示符优化

[root@dba1 ~]# echo $PS1
[\u@\h \W]\$
[root@dba1 ~]#

—1.1 临时修改

export PS1='[\u@\H \W]\$ '

—1.2 永久修改

第一个历程: 编写环境变量文件
vim /etc/profile 
export PS1='[\u@\H \W]\$ '

第二个历程: 查看确认
[root@oldboy-xiaodao.com.cn ~]# tail -1 /etc/profile
export PS1='[\u@\H \W]\$ '

第三个历程: 加载配置信息
source /etc/profile

—1.3 系统环境变量特点

1) 系统默认自带的变量
2) 变量都是有大写字母组成
3) 修改系统环境变量需要借助一个文件/etc/profile和一个命令export
4) 系统环境变量设置好,会影响所有用户

2. yum下载源进行优化

—2.1 yum下载软件原理

[root@dba1 ~]# cd /etc/yum.repos.d/
[root@dba1 /etc/yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo
CentOS-Debuginfo.repo CentOS-Sources.repo
[root@dba1 /etc/yum.repos.d]# head -20 CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

yum仓库: 一些经常使用的软件包(依赖包)
        存储一个所有软件汇总检索表
yum源文件: 指定下载软件的仓库信息
yum list --- 显示仓库中可以下载软件信息
yum repolist --- 显示可用软件仓库信息
yum reinstall --- 重新下载安装已经有的软件
yum erase --- 移动软件(一定不能使用此方法卸载软件)
rpm -e 软件名称 --nodepth --- 推荐卸载软件的方式

—2.2 yum下载源优化方法

wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
yum install https://repo.huaweicloud.com/epel/epel-release-latest-7.noarch.rpm
cp -a /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo
sed -i "s/metalink/#metalink/g" /etc/yum.repos.d/epel.repo
sed -i "s@https\?://download.example/pub@https://repo.huaweicloud.com@g" /etc/yum.repos.d/epel.repo

—2.3 epel仓库下载软件验证

[root@linux ~]yum install sl cowsay bash-completion-extras -y
[root@linux ~]sl
[root@linux ~]cowsay "Hello world"
[root@linux ~]animalsay "Hello world"

3. 安全服务优化

—3.1 selinux

利用selinux程序对root用户权限进行约束

如何关闭selinux程序
永久关闭: 修改配置文件
第一个历程: 修改配置文件
vim /etc/selinux/config
####底行输入:set nu 
7 SELINUX=disabled
enforcing - SELinux security policy is enforced. --selinux安全策略处于开启状态
permissive - SELinux prints warnings instead of enforcing. --selinux处于临时关闭状态 会有警告提示
disabled - No SELinux policy is loaded.   --selinux安全策略彻底关闭

第二个历程: 配置文件生效方法
永久关闭:
重启服务器

临时关闭: 
[root@oldboy-xiaodao.com.cn ~]# setenforce 
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@oldboy-xiaodao.com.cn ~]# setenforce 0  设置
[root@oldboy-xiaodao.com.cn ~]# getenforce 检查
Permissive

—3.2 firewalld(centos7)

临时关闭:
systemctl stop firewalld.service
检查
systemctl status firewalld.service
systemctl is-active firewalld.service

永久关闭:
systemctl disable firewalld.service

[root@oldboy-xiaodao.com.cn ~]# systemctl disable firewalld.service 
[root@oldboy-xiaodao.com.cn ~]# systemctl enable firewalld.service 

检查
systemctl status firewalld.service
systemctl is-enabled firewalld.service

—3.3 iptables(centos6)

临时关闭 
/etc/init.d/iptables stop
检查
/etc/init.d/iptables status

永久关闭
chkconfig iptables off
检查
chkconfig --list|grep ipt

—3.4 服务器防火墙运行状态建议

4. 字符编码优化

—4.1 什么字符编码

英语 --- 汉语 --- 乱码
五笔创始人 --- 字符编码 --- 英语 汉语
UTF-8 --- 通用编码类型(中文)
GBK --- 国际化通用编码类型

—4.2 字符编码信息修改

xshell软件的编码也应该是UTF-8,要和系统一致

临时修改 
[root@xiaoyong yum.repos.d]# echo $LANG
en_US.UTF-8
[root@xiaoyong yum.repos.d]# export LANG=en_US.GBK

永久修改
第一种方式
tail -1 /etc/profile
export LANG=en_US.GBK

第二种方式
tail -l /etc/locale.conf 
#LANG="en_US.UTF-8"
LANG="en_US.GBK"

既能永久修改,临时修改 
localectl set-locale LANG="en_US.UTF-8"
source /etc/locale.conf

—4.3 让系统字符信息尽量是中文显示

 

赞(0)
MySQL学习笔记 » 第4章:Linux系统基础优化