Linux系統優化

添加用戶 設置密碼 切換用戶

1.1 你的系統是什麼版本的?
CentOS 6.9
[root@oldboyedu42 ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@oldboyedu42 ~]# uname -r
2.6.32-696.el6.x86_64
[root@oldboyedu42 ~]# uname -m
x86_64
1.2 .添加用戶
[root@oldboyedu42 ~]# useradd oldboy
[root@oldboyedu42 ~]# id oldboy
uid=500(oldboy) gid=500(oldboy) groups=500(oldboy)
[root@oldboyedu42 ~]# id lilaoshi
id: lilaoshi: No such user
1.3 設置密碼
[root@oldboyedu42 ~]# 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.
1.4 切換用戶 切換爲oldboy
[root@oldboyedu42 ~]# su - oldboy
[oldboy@oldboyedu42 ~]$ whoami
oldboy
1.4.1 su 與 su - 區別
su命令和su -命令最大的本質區別就是:前者只是切換了root身份,但Shell環境仍然是普通用戶的Shell

#退出當前用戶
#ctrl + d
logout

1.5 什麼是變量
變量====書名字
$變量===讀書 看書裏面的內容

變量的名字 ======藏經閣武功祕籍名字 葵花寶典 === BAO
查看變量的內容=== 讀書 ==== echo $BAO
修改變量的內容=== 添加心得 ==== BAO=成功
欲練此功 必先自宮 如不自宮 也能成功

1.5.1 環境變量
1.大寫的
2.在系統的每個地方 都可以使用

[root@oldboyedu42 ~]# echo $PS1
[\u@\h \W]\$

#PS1存放的是 命令行的樣子

PS1="[\u@\h \W \t]\$"

IPTABLES和SELinux關閉

2.1 .修改文件永久-重啓Linux之後 合同生效
ls -l /etc/selinux/config

SELINUX=enforcing #修改SELinux的狀態
#enforcing SELinux已經開啓
#permissive SELinux臨時關閉,會提示警告信息
#disabled SELINUX徹底關閉

[root@oldboyedu42 ~]# grep "SELINUX=" /etc/selinux/config
SELINUX= can take one of these three values
SELINUX=disabled

2.2 命令行臨時--重啓Linux之後 失效

[root@oldboyedu42 ~]# #查看selinux狀態
[root@oldboyedu42 ~]# getenforce
Enforcing
[root@oldboyedu42 ~]# #當前SElinux狀態
[root@oldboyedu42 ~]#
#setenforce 1 ======= 開啓Selinux
0 ======= 臨時關閉SELinux
[root@oldboyedu42 ~]# setenforce 0
[root@oldboyedu42 ~]# getenforce
Permissive

不要給自己找任何利用 重啓服務器

小結:
1.臨時關閉SELinux-getenforce setenforce
2.永久關閉SElinux /etc/selinux/config
vim
sed
3.檢查

2.3 .防火牆 iptables
防火牆-看大門

什麼時候需要使用防火牆(保安)
1.服務器沒有公網的ip ,iptables關閉 高併發
2.服務器有公網ip(外網),iptables開啓

剛開始入門-iptables關閉

2.3.1 臨時關閉iptables

[root@oldboyedu42 ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@oldboyedu42 ~]# /etc/init.d/iptables stop
[root@oldboyedu42 ~]# /etc/init.d/iptables status
iptables: Firewall is not running.

2.3.2 永久關閉iptables

#不讓防火牆iptables 在開機自動啓動
#chkconfig 管理linux下面軟件 是否可以在開機自啓動
##查看iptables狀態 是否自啓動

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

[root@oldboyedu42 ~]# chkconfig iptables off
[root@oldboyedu42 ~]# chkconfig |grep ipt
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off

2.3.3 檢查
/etc/init.d/iptables status
chkconfig |grep ipt

小結:
https://www.processon.com/view/link/59e96ce1e4b00842bddfb5aa

查看中文的亂碼

3.1 在linux中查看中文亂碼如何解決?

3.1.1 預備姿勢
字符集 標識文字符號的方法

UTF-8 萬國碼 Linux默認字符集

GBK

爲何出現亂碼
遠程連接工具(xshell)字符集 與 系統的字符集不同

3.2 如何更改系統的字符集
3.2.1 第1個里程碑-查看系統使用的字符集
#LANG環境變量-存放的是系統的字符集和語音
[root@oldboyedu42 ~]# $LANG
-bash: en_US.UTF-8: command not found
[root@oldboyedu42 ~]# echo $LANG
en_US.UTF-8
語言.字符集
3.2.2 第2個里程碑-修改字符集-臨時-重新登陸後
[root@oldboyedu42 ~]# export LANG=zh_CN.UTF-8
[root@oldboyedu42 ~]# echo $LANG
zh_CN.UTF-8

3.2.3 第3個里程碑-永久生效
[root@oldboyedu42 ~]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"

source /etc/sysconfig/i18n

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章