Linux的优化

[root@Education-02 ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)

[root@Education-02 ~]# uname -r
2.6.32-696.el6.x86_64

 

在Linux中查看变量$

 

PS1 是系统的环境变量   环境变量一般是大写的 在系统中任何地方都可以使用 

[root@oldboyedu-01 ~]# #\u=====当前用户名 whoami
[root@oldboyedu-01 ~]# #\h 当前主机名 hostname
[root@oldboyedu-01 ~]# #\W 当前的位置 pwd

[root@Education-02 ~]# PS1='[\u@\h \w \t]$'
[root@Education-02 ~ 23:08:27]$

PS1 一般都不会改  控制命令行

uname  显示系统信息 

 -r 显示系统内核 

 -m 显示系统位数

Linux优化:

1、测试路通不通

2、是非有人劫财劫色

3、是有人提供服务 

添加用户 

Linux用户 :普通用户 、root用户 

如何添加一个用户  

useradd  

设置密码 passwd oldboy 

在Linux中与密码油罐的都不会显示 

 

[root@Education-02 ~ 23:16:54]$passwd oldboy
Changing password for user oldboy.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

 

退出当前账号 logout

id 显示用户的信息  

su 切换用户  switch user 切换用户 

su 与 su - 的区别 

Ctrl + d  退出当前 用户  

 

Xshell 重新连接 Ctrl shilt + R

 

SELinux:美国国家安全局的软件,目的:限制系统中的root中的权限  影响工作 一般选择关闭  

关闭SELinux 

临时关闭 #重启服务器之后失效 

[root@oldboyedu-01 ~]# getenforce

Enforcing
[root@oldboyedu-01 ~]# #enforcing selinux正在运行
[root@oldboyedu-01 ~]# #permissive selinux临时关闭 还是提示警告
[root@oldboyedu-01 ~]# #disabled selinux彻底关闭
[root@oldboyedu-01 ~]# setenforce  #只能临时关闭 无法变成 disabled状态 

永久关闭 :

编辑 /etc/selinux/config 文件  

SELINUXTYPE=enforce 改为 disabled

#   SELINUXTYPE=targeted   切记最后一行不能改  否则无法启用服务器 

永久配置 : 要重启之后才能生效  

getenforce  setenforce  

小结 :

1、临时关闭—setenforce

2、永久关闭

 

 iptables:

服务器对外使用,有外网,开启防火墙

服务器内网  (或者存在高并发 )   关闭

临时关闭防火墙

查看防火墙     /etc/init.d/iptables status

[root@Education-02 ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@Education-02 ~]# /etc/init.d/iptables stop

 

一般关闭两次  有时候一次关闭不掉  

开机自动启动  在Linux开机的时候回自动启动 

如何让iptables 在开机的时候不自动启动 

 

永久关闭

[root@Education-02 ~]# chkconfig | grep iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@Education-02 ~]# chkconfig iptables off

 

显示中文乱码排查过程 

什么是字符集:每个国际都有自己的文字,在计算机中表达出来,那就要用到字符集。

如何查看系统的字符集::

[root@Education-02 ~]# echo $LANG
en_US.UTF-8   #语言.字符集

UTF-8          万国码  系统默认的字符集 

GBK GB2312

###如何修改字符集  

环境变量 要往里面加东西的  前面要加上export 

临时生效:

[root@Education-02 ~]# export LANG=zh_CN.UTF-8
[root@Education-02 ~]# echo $LANG
zh_CN.UTF-8

永久生效:

[root@Education-02 ~]# cat /etc/sysconfig//i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
[root@Education-02 ~]# vim /etc/sysconfig/i18n
LANG="en_US.UTF-8"

[root@Education-02 ~]# source /etc/sysconfig/i18n

##显示中文乱码

####1.什么是字符集?
######表示字符 文字的方法
UTF-8 万国码 系统默认的字符集
GBK GB2312


####2.如何查看系统的字符集

[root@oldboyedu-01 ~]# echo $LANG
en_US.UTF-8
[root@oldboyedu-01 ~]# #语言.字符集


####3.如何修改字符集-临时
[root@oldboyedu-01 ~]# export LANG=zh_CN.UTF-8
[root@oldboyedu-01 ~]# echo $LANG
zh_CN.UTF-8

####4.如何修改字符集-永久
[root@oldboyedu-01 ~]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"

####5.生效
[root@oldboyedu-01 ~]# source /etc/sysconfig/i18n
[root@oldboyedu-01 ~]# echo $LANG
en_US.UTF-8

#####1.查看中文乱码的原因******
####1)linux使用的字符集
####2)远程连接工具使用的字符集
####1) 与 2) 不同 就会导致乱码

#####2.排查
####1)linux使用的字符集
####2)远程连接工具使用的字符集

#####3.解决
####方法1 修改远程连接工具字符集
####方法2 修改linux系统的字符集
####1.如何修改字符集-临时
####2.如何修改字符集-永久
####3.生效

 

posted @ 2019-09-08 12:18  熊哥爬行记  阅读(233)  评论(0编辑  收藏  举报