linux系统优化

第1章 linux系统优化

1.1 查看系统的版本

[root@oldboyedu-40 oldboy]# cat /etc/redhat-release

CentOS release 6.9 (Final)

 

1.1.1 内核版本 +64位

[root@oldboyedu-40 oldboy]# uname -r

2.6.32-696.el6.x86_64                  内核版本位2.6.32

[root@oldboyedu-40 oldboy]# uname -m

x86_64

 

1.2 创建 添加普通用户

[root@oldboyedu-40 oldboy]# useradd oldboy        添加一个叫oldboy的用户

[root@oldboyedu-40 oldboy]# passwd oldboy         为oldboy用户添加密码

Changing password for user oldboy.

New password:

BAD PASSWORD: it is too simplistic/systematic       提示密码太简单了

BAD PASSWORD: is too simple                    可以不理会

Retype new password:                            再次输入新密码

passwd: all authentication tokens updated successfully.(成功)     密码设置成功

 

1.2.1 使用这个用户

[root@oldboyedu-40 /]# su - oldboy               切换用户

[oldboy@oldboyedu-40 ~]$ whoami              显示当前在哪个用户下

oldboy

 

1.3 关闭SELinux功能

 

 第一个里程碑 -永久关闭selinux 修改selinux的配置文件

#enforcing   selinux默认状态 selinux已经开启 正在运行

#permissive    selinux临时关闭 显示警告

#disabled      selinux彻底关闭   

[root@oldboyedu-40 ~]# cat /etc/selinux/config           看一下文件里面的内容

 

# This file controls the state of SELinux on the s

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enfor

#     permissive - SELinux prints warnings instead

#     disabled - No SELinux policy is loaded.

SELINUX=enforcing

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

 

 [root@oldboyedu-40 ~]# sed 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config                     查看修改替换配置信息

 

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

 

[root@oldboyedu-40 ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config                   确定修改替换配置信息

 

[root@oldboyedu-40 ~]# grep "SELINUX=" /etc/selinux/config  查询是否更改成功

# SELINUX= can take one of these three values:

SELINUX=disabled

###selinux配置文件生效--需要重启服务器

 #不要给自己找任何理由重启服务器

第二个里程碑--临时关闭selinux

  1. ###查看selinux是否正在运行

[root@oldboyedu-40 ~]# getenforce

Enforcing                            selinux正在运行

2.临时关闭selinux

[root@oldboyedu-40 ~]# setenforce

usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]        1是运行 0是关闭

[root@oldboyedu-40 ~]# setenforce 0   

[root@oldboyedu-40 ~]# getenforce

Permissive

小结:

如何关闭selinux

永久关闭selinux    /etc/selinux/config
临时关闭 selinux    setenforce

 

1.4 关闭防火墙iptables

###防火墙--------相当于我们大楼的门卫 保安

      ###工作中如何使用 何时开启关闭 防火墙

  1. 大楼的门口 所有人都可以进进出出     服务器可以让用户使用(全世界)开启防火墙
  2. 内部教室的门  内部人员 学生 老师 出入  不开启防护墙
  3. 刚开始学习linux的时候 也要关闭防火墙
  4. 高并发 访问量大的时候也要关闭

1.4.1 查询防火墙是否正在运行

[root@oldboyedu-40 ~]# /etc/init.d/iptables  status

Table: filter

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination        

1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0          

3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0          

4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22

5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

 

Chain FORWARD (policy ACCEPT)

num  target     prot opt source               destination        

1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

 

Chain OUTPUT (policy ACCEPT)

num  target     prot opt source               destination         

 

1.4.2 临时关闭防火墙

[root@oldboyedu-40 ~]# /etc/init.d/iptables stop

iptables: Setting chains to policy ACCEPT: filter                                                [  OK  ]

iptables: Flushing firewall rules:              [  OK  ]

iptables: Unloading modules:                    [  OK  ]

[root@oldboyedu-40 ~]# /etc/init.d/iptables stop

[root@oldboyedu-40 ~]# /etc/init.d/iptables  status

iptables: Firewall is not running.

 

1.4.3 永久关闭iptables

#让iptables防火墙 在开机的时候不启动

[root@oldboyedu-40 ~]# chkconfig  |grep ipt

iptables         0:off      1:off      2:on       3:on       4:on       5:on       6:off

[root@oldboyedu-40 ~]# chkconfig iptables off

[root@oldboyedu-40 ~]# chkconfig  |grep ipt

iptables         0:off      1:off      2:off      3:off      4:off      5:off      6:off

[root@oldboyedu-40 ~]# /etc/init.d/iptables status          检查iptables状态

iptables: Firewall is not running.   

 

1.5 linux中文显示设置(如何防止显示中文乱码)                    

什么是字符集?

常用的字符集 UTF-8

如何查看字符集 变量中

查询当前系统使用的字符集

[root@oldboyedu-40 ~]# echo $LANG

en_US.UTF-8

 

LANG 环境变量

  1. 名字是大写的
  2. 在系统中 大部分角落 都可以使用

1.5.1 临时修改系统的语言和字符集

[root@oldboyedu-40 ~]# export LANG=zh_CN.UTF-8    修改字符集

[root@oldboyedu-40 ~]# echo $LANG                  查看字符集

zh_CN.UTF-8

 

修改后 setup 会中文显示

1.5.2 永久改变系统的语言和字符集

[root@oldboyedu-40 ~]# cat /etc/sysconfig/i18n

LANG="en_US.UTF-8"

SYSFONT="latarcyrheb-sun16"

 

将LANG="en_US.UTF-8"修改成LANG="zh_CN.UTF-8"就是修改了字符集

1.5.3 生效

source /etc/sysconfig/i18n

 

1.5.4 中文显示乱码的原因

  系统的字符集 echo $LANG 和远程连接软件 (xshell)的字符集不同

解决方法:

修改远程连接软件(xshell)的字符集

修改linux系统的字符集 1.临时生效:export LANG=要修改的字集

2.永久:修改/etc/sysconfig/i18n文件中的LANG="en_US.UTF-8"

修改后让其生效 source  /etc/sysconfig/i18n

 

 

 

 

本博文中所使用的系统版本为: CentOS release 6.9 (Final) 内核版本为: 2.6.32-696.10.1.el6.x86_64 linux正在持续学习中

posted @ 2017-10-26 13:41  巴黎斜塔  阅读(183)  评论(0编辑  收藏  举报