1.1 出現亂碼解決方法
更改語言
export.GB2312 echo $LANG en_US.GB2312
系統當前使用的字符集
1、echo $LANG
2、看你當前遠程連接工具的使用語言(軟件的字符集)
#1.系統當前使用的字符集 echo $LANG en_US.GB2312 #2.看你遠程連接的軟件的字符集 export.UTF-8 echo $LANG en_US.UTF-8 zh_CN.UTF-8 中文
/etc/syscionfig/i18n 永久生效
###恢復原有的英文環境
\cp /etc/sysconfig/i18n.bak/etc/sysconfig/i18n source/etc/sysconfig/i18n [root@oldboyedu-35 ~]# echo $LANG en_US.UTF-8
1.2 03 更新yum源信息
# 03:更新yum源信息
mv /etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo mv /etc/yum.repos.d/epel.repo/etc/yum.repos.d/epel.repo.backup mv /etc/yum.repos.d/epel-testing.repo/etc/yum.repos.d/epel-testing.repo.backup wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
1.3 04 關閉selinux
# 04:關閉selinux
sed -i 's#SELINUX=.*#SELINUX=disabled#g'/etc/selinux/config sed -i 's/SELINUX=enforcing/SELINUX=disabled/'/etc/selinux/config grep SELINUX=disabled /etc/selinux/config setenforce 0 getenforce
1.4 05 關閉iptables
# 05:關閉iptables
/etc/init.d/iptables stop /etc/init.d/iptables stop chkconfig iptables off
1.5 06 精簡開機自啓動項
# 06:精簡開機自啓動項
chkconfig|egrep -v"crond|sshd|network|rsyslog|sysstat"|awk '{print"chkconfig",$1,"off"}'|\ bash export chkconfig --list|grep 3:on
1.6 07 提取username可以利用sudo
# 07:提權oldboy可以利用sudo
useradd oldboy echo 123456|passwd --stdin oldboy \cp /etc/sudoers /etc/sudoers.ori echo "oldboy ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers tail -1 /etc/sudoers visudo -c
1.7 08 字符集
# 08:設置系統中文字符集
cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori echo 'LANG="en_US.UTF-8"' >/etc/sysconfig/i18n source /etc/sysconfig/i18n echo $LANG
1.8 加大文件描述符
# 10:加大文件描述符
echo '* - nofile 65535 '>>/etc/security/limits.conf
tail -1 /etc/security/limits.conf
ulimit -SHn 65535
ulimit -n
1.9 優化系統內核信息
# 11:優化系統內核信息
cat >>/etc/sysctl.conf<<EOF net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_keepalive_time = 600 net.ipv4.ip_local_port_range = 4000 65000 net.ipv4.tcp_max_syn_backlog = 16384 net.ipv4.tcp_max_tw_buckets = 36000 net.ipv4.route.gc_timeout = 100 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1 net.core.somaxconn = 16384 net.core.netdev_max_backlog = 16384 net.ipv4.tcp_max_orphans = 16384 #以下參數是對iptables防火牆的優化,防火牆不開會提示,可以忽略不理。 net.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_tcp_timeout_established= 180 net.netfilter.nf_conntrack_tcp_timeout_time_wait =120 net.netfilter.nf_conntrack_tcp_timeout_close_wait =60 net.netfilter.nf_conntrack_tcp_timeout_fin_wait =120 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.wmem_max = 16777216 net.core.rmem_max = 16777216 EOF sysctl -p
1.10 安裝系統常用小軟件
yum install lrzsz nmap tree dos2unix nc -y
1.11小功能優化
PS1="\[\e[32;1m\][\u@\h \W]\\$\[\e[0m\]" >>/etc/bashrc ##小功能優化
sed -i.bak 's@#UseDNS yes@UseDNS no@g;s@^GSSAPIAuthentication yes@GSSAPIAuthentication no@g'/etc/ssh/sshd_config /etc/init.d/sshd reload
1.13 Linux基礎優化與安全重點小結
01.不用root登錄管理系統,而以普通用戶登錄通過sudo授權管理。
02.更改默認的遠程連接SSH服務端口,禁止root用戶遠程連接,甚至要更改SSH服務只監聽內網IP。
03.定時自動更新服務器的時間,使其和互聯網時間同步。
04.配置yum更新源,從國內更新源下載安裝軟件包。
05.關閉SELinux及iptables在工作場景中,如果有外部IP一般要打開iptables,高併發高流量的服務器可能無法開啓。
06.調整文件描述符的數量,進程及文件的打開都會消耗文件描述符數量。
07.定時自動清理郵件臨時目錄垃圾文件,防止磁盤的inodes數被小文件佔滿注意Centos6和Centos5要清除的目錄不同。
08.精簡併保留必要的開機自啓動服務(如crond、sshd、network、rsyslog、sysstat)。
09.Linux內核參數優化/etc/sysctl.conf,執行sysctl -p生效。
10.更改系統字符集爲“zh_CN.UTF-8”,使其支持中文,防止出現亂碼問題。
11.鎖定關鍵系統文件如/etc/passwd、/etc/shadow、/etc/group、/etc/gshadow、/etc/inittab,
處理以上內容後把chattr、lsattr改名爲oldboy,轉移走,這樣就安全多了。
12.清空/etc/issue、/etc/ issue.net,去除系統及內核版本登錄前的屏幕顯示。
13.清除多餘的系統虛擬用戶賬號。
14.爲grub引導菜單加密碼。
15.禁止主機被ping。
16.打補丁並升級有已知漏洞的軟件。