系统基础优化--iptables selinux 系统字符集

1.2、系统优化讲解

1.2.1、查看系统环境

01、查看系统版本

[[email protected] ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
[[email protected] ~]#

02、查看系统架构信息

[[email protected] ~]# uname -m
x86_64
[[email protected] ~]#

03、查看内核信息

[[email protected] ~]# uname -r
2.6.32-696.el6.x86_64
[[email protected] ~]#

04、uname参数

1.2.2、基础优化-创建系统管理用户(普通用户)

用户分类:

root用户---超级管理员用户-->皇帝

oldboy用户---普通用户--->平民

01、创建用户

[[email protected] ~]# useradd oldboy
[[email protected] ~]#

02、从用户直接切换到oldboy用户

[[email protected] ~]# su - oldboy
[[email protected] ~]$

03、查看当前用户

[[email protected] ~]$ whoami 
oldboy
[[email protected] ~]$

04、为普通用户设置密码

说明:如果用户需要重置密码。需要以root身份执行passwd命令

[[email protected] ~]# passwd 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.    #表示密码设置成功
[[email protected] ~]#

06、免交互创建用户密码

[[email protected] ~]# useradd oldgirl
[[email protected] ~]# echo 123456|passwd --stdin oldgirl
Changing password for user oldgirl.
passwd: all authentication tokens updated successfully.
[[email protected] ~]#

07、切换用户说明

总结:su – 切换用户命令说明

01、root用户   切换   普通用户     不需要密码

02、普通用户    切换   root用户    需要密码

03、普通用户    切换   普通用户     需要密码

1.2.3、命令提示符的优化

知识铺垫

变量信息  环境变量信息

变量概念实践说明

[[email protected] ~]# oldboy=123456
[[email protected] ~]# echo $oldboy
123456
[[email protected] ~]# oldboy=aaaaaaaaaaaaaaaaa
[[email protected] ~]# echo $oldboy
aaaaaaaaaaaaaaaaa
[[email protected] ~]#

环境变量:系统中已经定义好的变量信息,并且系统中已经定义好的变量信息,通常用大写字母表示

01、环境变量 PS1

02、修改PS1 环境变量

临时修改

[[email protected] ~]# echo $PS1
[\[email protected]\h \W]\$
[[email protected] ~]# export PS1="[\[email protected]\h \W\A]\$"
[[email protected] ~10:50]$export PS1="[\[email protected]\h \W \T]\$"
[[email protected] ~ 10:50:47]$
[[email protected] ~ 10:51]$export PS1="[\[email protected]\h \W \A]\$ "
[[email protected] ~ 10:51]$ 
   永久生效修改方法
[[email protected] ~ 10:53]$ echo 'export PS1="[\[email protected]\h \W \A]\$ "' >>/etc/profile
[[email protected] ~ 10:53]$ tail -1 /etc/profile
export PS1="[\[email protected]\h \W \A]\$ "
[[email protected] ~ 10:53]$ source /etc/profile
[[email protected] ~ 10:53]$

查看系统所有环境变量信息并过滤出命令提示符PS1的变量

[[email protected] ~ 10:55]$ set |grep PS1
PS1='[\[email protected]\h \W \A]$ '
[[email protected] ~ 10:56]$

1.2.4、系统基础优化---安全服务优化

1、安全服务软件---selinux(在一定程度上限制root用户权限)

2、安全服务软件---iptables(网络安全隔离的服务)

ps:系统初始化使用时,尽量将安全服务关闭

1、selinux软件如何关闭

01、临时关闭

查看此时系统selinux服务状态

[[email protected] ~ 11:04]$ getenforce 
Enforcing       #处于开启状态
[[email protected] ~ 11:04]$

临时关闭selinux服务

[[email protected] ~ 11:18]$ setenforce 
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[[email protected] ~ 11:19]$ setenforce 0
[[email protected] ~ 11:19]$ getenforce 
Permissive      #处于临时关闭状态
[[email protected] ~ 11:19]$

查看系统selinux服务配置信息

[[email protected] ~ 11:07]$ cat /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.
    #selinux服务处于开启状态
#     permissive - SELinux prints warnings instead of enforcing.
    #selinux临时关闭状态,还会有安全告警提示信息
#     disabled - No SELinux policy is loaded.
    #selinux彻底关闭状态
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
 
 
[[email protected] ~ 11:07]$

02、永久关闭selinux

修改selinux配置文件

[[email protected] ~ 11:17]$ sed -i.bak 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[[email protected] ~ 11:17]$ grep SELINUX /etc/selinux/config
# SELINUX= can take one of these three values:
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
SELINUXTYPE=targeted 
[[email protected] ~ 11:18]$

其他方法

[[email protected] ~ 11:29]$ sed -i.bak '7s#enforcing#disabled#g' /etc/selinux/config
[[email protected] ~ 11:29]$

03、临时关闭与永久关闭一起

setenforce 0
sed -i.bak '7s#enforcing#disabled#g' /etc/selinux/config
sed -i.bak 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

2、iptables服务如何关闭

01、临时关闭iptables

[[email protected] ~ 11:45]$ /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[[email protected] ~ 11:47]$

02、查看iptables状态

[[email protected] ~ 11:47]$ /etc/init.d/iptables status
iptables: Firewall is not running.
[[email protected] ~ 11:48]$

03、永久关闭iptables

查看iptables服务是否处于开启启动

[[email protected] ~ 11:52]$ chkconfig |grep iptables
iptables         0:off   1:off   2:on    3:on    4:on    5:on    6:off
#这里 3:on  表示在开机会自动启动 iptables
[[email protected] ~ 11:52]$

关闭iptables开机自动启动

[[email protected] ~ 11:52]$ chkconfig iptables off
[[email protected] ~ 11:54]$
在检查一下是否关闭开机启动iptables服务
[[email protected] ~ 11:54]$ chkconfig |grep iptables
iptables         0:off   1:off   2:off   3:off   4:off   5:off   6:off
#这里 3:on  表示在开机不会启动iptables
[[email protected] ~ 11:55]$

1.2.5、系统基础优化---防止系统乱码

01、制造出乱码情况(字符集设定不对)

修改一个错误的字符集环境变量

[[email protected] ~ 12:24]$
[[email protected] ~ 12:24]$
[[email protected] ~ 12:24]$
查看是否出现乱码
[[email protected] ~ 12:25]$ setup

02、避免出现乱码---正确修改字符集

[[email protected] ~ 12:28]$ LANG=en_US.UTF-8

[[email protected] ~ 12:28]$ echo $LANG

en_US.UTF-8

[[email protected] ~ 12:29]$

03、永久修改字符集

默认字符集配置文件

vim /etc/sysconfig/i18n

修改或添加

LANG="en_US.UTF-8"

保存退出

使配置文件生效

source /etc/sysconfig/i18n

检查字符集是否修改正确

[[email protected] ~ 12:31]$ echo $LANG

en_US.UTF-8

[[email protected] ~ 12:32]$

04、修改中文字符集(不建议设置)

临时修改,系统中文字符集

[[email protected] ~ 12:42]$ LANG=zh_CN.UTF-8

[[email protected] ~ 12:42]$

检查是否设置成功

[[email protected] ~ 12:46]$ chkconfig |grep iptables

iptables         0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭

[[email protected] ~ 12:47]$

永久修改系统中文字符集

vim /etc/sysconfig/i18n

修改或添加

LANG="zh_CN.UTF-8"

保存退出

加载配置

[[email protected] ~ 12:47]$ source /etc/sysconfig/i18n

检查是否修改成功

[[email protected] ~ 12:47]$ chkconfig |grep iptables
iptables         0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭
[[email protected] ~ 12:47]$
[[email protected] ~ 12:47]$ /etc/init.d/iptables status
iptables:未运行防火墙。
[[email protected] ~ 12:47]$[object Object]

原文地址:http://blog.51cto.com/13673885/2140519

时间: 2024-07-29 11:54:59

系统基础优化--iptables selinux 系统字符集的相关文章

linux系统基础优化

1.Linux系统基础优化 一.关闭SELinux功能 Selinux是什么? 安全工具,控制太严格,生产环境不用它,使用其他安全手段. 简介: SELinux带给Linux的主要价值是:提供了一个灵活的,可配置的MAC机制. Security-Enhanced Linux (SELinux)由以下两部分组成: 1) Kernel SELinux模块(/kernel/security/selinux) 2) 用户态工具 SELinux是一个安全体系结构,它通过LSM(Linux Security

Linux 系统基础优化和常用命令

目录 Linux 系统基础优化和常用命令 软连接 tar解压命令 gzip命令 netstart命令 ps命令 kill命令 killall命令 SELinux功能 iptables防火墙 Linux中文显示设置(防止中文乱码) df 命令 tree命令 设置主机名 DNS 查看Linux的dns, 唯一配置文件 本地强制dns解析文件 /etc/hosts nslookup命令 计划任务crond服务 软件包管理 windows程序 macos程序 RPM软件包管理器 实例 rpm安装软件 r

Linux服务器企业集群架构部署搭建(一)----环境配置要求与系统基础优化

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想. 本文作者:燁未央_Estelle版权声明:测试学习,不足之处,欢迎指正.允许转载,转载时请务必以超链接形式标明文章原始出处.作者信息和本声明 第一章 集群架构搭建部署目标1.1 本次架构部署配置概况提示,本次集群架构所使用的服务器均为VM虚拟机进行模拟搭建测试及学习. ①两台linux服务器作为负载均衡服务器(LVS-01/LVS-02),基本模式:LVS-DR+keepalived.负责分发所

系统基础优化

一.创建系统管理用户 1.系统用户分类 root用户:超级管理员用户,linux的皇帝 其他用户:普通用户,例如自建用户oldboy 2.创建oldboy普通用户 1)创建用户名 useradd oldboy 2)创建用户密码 登录root用户的状态下给oldboy设置密码:passwd oldboy root状态下免交互设置密码:echo "123456"|passwd --stdin oldboy 给当前登录用户更改密码:passwd 3.用户之间的切换 1)root用户切换到普通

系统基础优化及查看系统信息命令

01. 操作系统基础优化1.操作系统字符优化查看默认编码信息:echo $LANGen_US.UTF-8临时修改:LANG=zh_CN.utf8永久修改:vi /etc/locale.confLANG="zh_CN.utf8"临时永久都做修改:localectl set-locale LANG="zh_CN.gbk"2.系统远程连接优化vi /etc/ssh/sshd_config --- 远程服务配置文件115 UseDNS no --- 是否开启DNS反向解析过

Linux系统基础优化及常用命令

Linux基础系统优化 引言没有,只有一张图. Linux的网络功能相当强悍,一时之间我们无法了解所有的网络命令,在配置服务器基础环境时,先了解下网络参数设定命令. ifconfig 查询.设置网卡和ip等参数 ifup,ifdown    脚本命令,更简单的方式启动关闭网络 ip 符合指令,直接修改上述功能 在我们刚装好linux的时候,需要用xshell进行远程连接,那就得获取ip地址,有时候网卡默认是没启动的,Linux也就拿不到ip地址,因此我们得手动启动网卡 #编辑网卡配置文件 vim

8,Linux系统基础优化及常用命令

Linux基础系统优化 引言没有,只有一张图. Linux的网络功能相当强悍,一时之间我们无法了解所有的网络命令,在配置服务器基础环境时,先了解下网络参数设定命令. ifconfig 查询.设置网卡和ip等参数 ifup,ifdown    脚本命令,更简单的方式启动关闭网络 ip 符合指令,直接修改上述功能 在我们刚装好linux的时候,需要用xshell进行远程连接,那就得获取ip地址,有时候网卡默认是没启动的,Linux也就拿不到ip地址,因此我们得手动启动网卡 #编辑网卡配置文件 vim

linux系统基础优化16条知识汇总

优化的总结: 1.不用root管理,以普通用户的名义通过sudo授权管理. 2.更改默认的远程连接SSH服务端口,禁止root用户远程连接,甚至 要更改只监听内网IP. 3.定时自动更新服务区时间,使其和互联网时间同步. 4.配置yum跟新源,从更新源下载安全软件包. 5.关闭seLinux及iptables(在工作场景中,如果有外部IP一般要打开 6.调整文件描述符的数量,进程及文件的打开都会消耗文件描述. 7.定时自动清理邮件目录垃圾文件,防止inodes节点被占满 (注意Centos6和C

linux系统基础优化和安全重点小结

本文描述一些基本的系统优化知识点,为适应批量配置,所有代码为非交互式配置方法,可在crt中通过命令窗口做简单的批量处理. 不用root登录管理系统,而以普通用户登录通过sudo授权管理.作为一个例子这里新建一个用户,并做sudo提权 useradd gotimmygo echo 123456|passwd --stdin gotimmygo \cp /etc/sudoers{,ori} echo "gotimmygo ALL=(ALL) NOPASSWD:ALL">>/et