Linux之系统优化


系统环境变量PS1

查看系统环境变量
echo $PS1      
#PS1 系统环境变量
##一般都是大写的,在系统中任何的地方都可以使用。
[root@oldboyedu-01 ~]# echo $PS1
[\u@\h \W]\$
[root@oldboyedu-01 ~]# #\u=====当前用户名 whoami
[root@oldboyedu-01 ~]# #\h     当前主机名 hostname 
[root@oldboyedu-01 ~]# #\W     当前的位置 pwd
[root@oldboyedu-01 ~]# PS1='[\u@\h \W \t]\$'    加了一个时间\t,就会在命令行前面显示时间

添加用户

Linux用户分为两种,root用户和普通用户

添加用户命令:useradd

查看用户:id

设置密码:passwd

切换用户:su - 用户名

思考:su   和su  -   的区别是什么?

快捷键:   ctrl + d  退出当前用户


关闭 SElinux

SElinux是限制root用户的权限的软件


临时关闭-重启服务器失效

扫描二维码关注公众号,回复: 3592118 查看本文章
[root@oldboyedu-01 ~]# #查询selinux状态
[root@oldboyedu-01 ~]# getenforce 
Enforcing

# 共3种状态

[root@oldboyedu-01 ~]# #enforcing   selinux正在运行
[root@oldboyedu-01 ~]# #permissive  selinux临时关闭 还是提示警告
[root@oldboyedu-01 ~]# #disabled    selinux彻底关闭

#临时关闭

[root@oldboyedu-01 ~]# setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@oldboyedu-01 ~]# setenforce 0
[root@oldboyedu-01 ~]# getenforce 
Permissive
[root@oldboyedu-01 ~]# 重启服务器,又会开启


永久关闭-重启服务器生效

需要使用vim修改/etc/selinux/config中的文件内容

[root@oldboyedu-01 ~]# vim /etc/selinux/config

# 然后查看

[root@oldboyedu-01 ~]# grep "=disabled" /etc/selinux/config 
SELINUX=disabled
[root@oldboyedu-01 ~]# grep "disabled" /etc/selinux/config 
#     disabled - No SELinux policy is loaded.
SELINUX=disabled


关闭Iptables

即关闭防火墙


临时关闭

#查询防火墙是否在运行 
/etc/init.d/iptables  status
[root@oldboyedu-01 ~]# /etc/init.d/iptables  stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@oldboyedu-01 ~]# /etc/init.d/iptables  stop
[root@oldboyedu-01 ~]# /etc/init.d/iptables  status 
iptables: Firewall is not running.


永久关闭

开机自动启动
#让iptables在开机的时候 不自动启动
命令:chkconfig 
[root@oldboyedu-01 ~]# chkconfig |grep ipt
iptables           0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@oldboyedu-01 ~]# chkconfig iptables off
[root@oldboyedu-01 ~]# chkconfig |grep ipt
iptables           0:off    1:off    2:off    3:off    4:off    5:off    6:off


显示中文乱码的排查

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.生效

猜你喜欢

转载自www.cnblogs.com/yxiaodao/p/9790684.html