linux优化——永久关闭SELinux和iptables,修改字符集,命令行参数补齐

本文介绍了如何在CentOS系统中永久关闭SELinux和iptables,以及如何修改字符集和启用命令行参数补全。步骤包括修改 `/etc/selinux/config` 文件设置SELINUX为disabled,使用 `setenforce` 和 `chkconfig` 命令关闭iptables,通过调整 `/etc/sysconfig/i18n` 文件改变系统字符集,并安装bash-completion以实现命令补全功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

永久关闭SELinux

[root@centos ~]# vi /etc/selinux/config   #将enforcing改为disabled
# 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
                                                                                   
"/etc/selinux/config" 13L, 457C written
[root@centos ~]# setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@centos ~]# setenforce 0
[root@centos ~]# getenforce
Permissive

永久关闭iptables

对于iptables关闭或开启建议

1)服务器可以被外界访问(公网/外网ip,iptables开启

2)内部环境(局域网/没网ipiptables关闭

3)高并发的iptables关闭

 

a) 临时关闭iptables

通过脚本关闭: /etc/init.d/iptables  stop

通过服务关闭: service iptables stop

查看当前iptables的状态:/etc/init.d/iptables status

 脚本和服务关闭等价,但脚本关闭支持tab补全,建议使用脚本关闭。

b) 永久关闭iptables

注:管理开机自启动服务(软件)-chkconfig

查看iptbales是否开机自启动:chkconfig |grep iptable或者chkconfig --list|grep iptables,两者等价

关闭iptbaleschkconfig iptables off,更精细的关闭是chkconfig --level 3 iptables  off

[root@centos ~]# /etc/init.d/iptables  stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@centos ~]# service iptables stop
[root@centos ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
[root@centos ~]# chkconfig --list|grep iptables
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@centos ~]# chkconfig |grep iptables
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@centos ~]# chkconfig --level 3 iptables off
[root@centos ~]# chkconfig |grep iptables

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

修改字符集

字符集显示不正常可能是客户端(xshell/secureCRT/putty)或虚拟机端字符集设置问题。针对虚拟机

查看字符集:echo  $LANG

临时修改字符集(立即生效,重新登录系统失效):export LANG=zh_CN.UTF-8或LANG=zh_CN.UTF-8

注:只要修改环境变量就必须在前面加export

    中文字符集:zh_CN.UTF-8

    英文字符集:en_US.UTF-8

永久修改字符集(source或.或重启生效):修改配置文件/etc/sysconfig/i18n

修改完后:使用source  /etc/sysconfig/i18n 使其生效


[root@centos ~]# echo $LANG
en_US.UTF-8
[root@centos ~]# echo $(LANG)
-bash: LANG: command not found
[root@centos ~]# export LANG=en
[root@centos ~]# echo $LANG
en
[root@centos ~]# LANG=en
[root@centos ~]# echo $LANG
en
[root@centos ~]# cat /etc/sysconfig/i18n 
LANG="en_US.UTF-8"

SYSFONT="latarcyrheb-sun16"

[root@centos ~]# vi  /etc/sysconfig/i18n 

[root@centos ~]# . /etc/sysconfig/i18n 
[root@centos ~]# source /etc/sysconfig/i18n
[root@centos ~]# cat /etc/sysconfig/i18n
LANG="zh_cn.UTF-8"

SYSFONT="latarcyrheb-sun16"

命令行参数补齐

最小化安装centos6.9,无法直接使用yum安装bash-completion。先安装EPEL (Extra Packages for Enterprise Linux)

yum provides epel*   *completion  查找

yum install epel-release -y            安装epel源

yum install bash-completion -y

退出登录,重新登录即可使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值