码迷,mamicode.com
首页 > 其他好文 > 详细

centos基础优化(一)

时间:2014-06-10 22:45:35      阅读:399      评论:0      收藏:0      [点我收藏+]

标签:linux   centos   系统优化   

Centos基础优化

一、给系统添加普通账户

在生产环境当中root账户是不允许被使用的,所以我们需要给系统增加一些普通账户来进行日常维护操作使用。

增加账户命令如下:

[root@localhost ~]# useradd jerry

[root@localhost ~]# passwd jerry

Changing password for user jerry.

New password:

BAD PASSWORD: it is too simplistic/systematic

BAD PASSWORD: is too simple

Retype new password:

passwd: all authentication tokens updated successfully.

[root@localhost ~]# su - jerry

[jerry@localhost ~]$ su -

Password:

 

二、修改系统yum源地址

    系统默认yum源是国外centos官方地址源,在后续进行yum安装更新时会比较慢,为了节约时间提高效率,我们把yum源改为国内的yum源。

一种方法是直接编辑yum的配置文件:

[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo

这种方法不推荐,因为修改位置较多且容易输出错误,所以建议用下面的方法进行更改;

  1. cd到yum配置文件目录下:

[root@localhost ~]# cd/etc/yum.

yum.conf     yum.repos.d/

[root@localhost ~]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# ls

CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo


  1. 备份配置文件:

[root@localhost yum.repos.d]# /bin/mv CentOS-Base.repoCentOS-Base.repo.backup

[root@localhost yum.repos.d]# ls

CentOS-Base.repo.backup CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo


  1. 下载sohu的yum配置文件进行替换:

注:sohu镜像源支持centos4,5;

163镜像源支持centos5,6;

[root@localhost yum.repos.d]# wgethttp://mirrors.sohu.com/help/CentOS-Base-sohu.repo

--2013-12-24 04:49:16-- http://mirrors.sohu.com/help/CentOS-Base-sohu.repo

Resolving mirrors.sohu.com... 119.188.36.70

Connecting to mirrors.sohu.com|119.188.36.70|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 2299 (2.2K) [application/octet-stream]

Saving to: ?.entOS-Base-sohu.repo?

100%[===================================================================================>]2,299       --.-K/s   in 0.02s  

2013-12-24 04:49:17 (104 KB/s) - ?.entOS-Base-sohu.repo?.saved[2299/2299]

[root@localhost yum.repos.d]# ls

CentOS-Base.repo.backup CentOS-Base-sohu.repo CentOS-Debuginfo.repo CentOS-Media.repo  CentOS-Vault.repo

[root@localhost yum.repos.d]# /bin/mv CentOS-Base-sohu.repo CentOS-Base.repo

[root@localhost yum.repos.d]# ls

CentOS-Base.repo CentOS-Base.repo.backup CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo

   

4.导入key之后更新yum:

[root@localhost yum.repos.d]# rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY*

[root@localhost yum.repos.d]# yum upgrade


注: update和upgrade区别

yum -y update  
    升级所有包,改变软件设置和系统设置,系统版本内核都升级 
        yum-y upgrade 
    升级所有包,不改变软件设置和系统设置,系统版本升级,内核不改变

 

5.查看某个rpm包是否安装:

[root@localhost yum.repos.d]# rpm -qa|grep lrzsz

lrzsz-0.12.20-27.1.el6.x86_64

[root@localhost yum.repos.d]# rpm -qa|grep sysstat

sysstat-9.0.4-22.el6.x86_64


6.如果有哪个包组没有安装可以执行下面的命令进行查找安装:

[root@localhostyum.repos.d]# yum grouplist

如要安装包组中的Base:

[root@localhost yum.repos.d]# yum groupinstall "Base" –y


三、优化SELINUX

        在生产环境当中selinux不是必要的,而且会给我们日后工作当中带来很多困扰,所以我们针对selinux的优化就是把selinux关闭。

    1.编辑selinux配置文件

[root@localhost ~]# vim/etc/selinux/config

 

  1

  2 # This file controls the state of SELinuxon the system.

  3 # SELINUX= can take one of these threevalues:

  4 #    enforcing - SELinux security policy is enforced.

  5 #    permissive - SELinux prints warnings instead of enforcing.

  6 #    disabled - No SELinux policy is loaded.

  7 SELINUX=disabled

  8 # SELINUXTYPE= can take one of these twovalues:

  9 #    targeted - Targeted processes are protected,

 10 #    mls - Multi Level Security protection.

 11 SELINUXTYPE=targeted

 

更改第7行,把enforcing改为disabled;

检查selinux状态:

[root@localhost ~]#getenforce

Enforcing

[root@localhost ~]#setenforce 0 ==》#使selinux配置文件临时生效

[root@localhost ~]#getenforce

Permissive


四、修改运行级别

        将系统默认运行级别修改为3。

1.查看当前运行级别

     [root@localhost~]# runlevel

N 3

2.编辑/etc/inittab配置文件

[root@localhost~]# vim /etc/inittab

 

17 #Default runlevel. The runlevels used are:

18 #   0 - halt (Do NOT set initdefault to this)

19 #   1 - Single user mode

20 #   2 - Multiuser, without NFS (The same as 3,if you do not have networking)

21 #   3 - Full multiuser mode

22 #   4 - unused

23 #   5 - X11

24 #   6 - reboot (Do NOT set initdefault to this)

25 #

26 id:3:initdefault:


五、修改ssh端口号

       系统默认ssh端口为22,为了安全我们需要把默认端口号改为65518陌生端口。

  1. 查看ssh配置文件

[root@localhost~]# vim /etc/ssh/sshd_config

插入以下命令:

 ###by jerry 20140101###  ==》修改人及日期

 Port 65518              ==》修改端口

 PermitRootLogin no       ==》不允许root登陆

 PermitEmptyPasswords no  ==》不允许空密码登陆

 UseDNS no              ==》不用DNS解析

 ###by jerry 20140101###


  1. 关闭系统防火墙

临时关闭iptables

[root@localhost~]# /etc/init.d/iptables stop

 

永久关闭iptables

[root@nagios~]# chkconfig --level 35 iptables off

 

界面设置关闭iptables

[root@localhost~]# setup


选择Firewallconfiguration

bubuko.com,布布扣

在[ ]中取消*号,OK退出。

bubuko.com,布布扣

重启iptables服务;

[root@nagios~]# /etc/init.d/iptables restart


六、系统默认语言修改

1.修改系统默认语言

[root@nagios~]# vim /etc/sysconfig/i18n

 

LANG="en_US.UTF-8"

LANG="zh_CN.UTF-8"

 

七、修改系统主机名

1.永久修改系统主机名

[root@nagios~]# vim /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=nagios

  1. 临时修改系统主机名

[root@nagios~]# hostname nagios

 

八、系统时间同步

1.使用ntpdate命令

[root@lnmp~]# vim /etc/crontab

*/1 * * ** root ntpdate 202.120.2.101

每分钟进行时间同步。


本文出自 “青春_未来” 博客,请务必保留此出处http://stone880117.blog.51cto.com/1664014/1423764

centos基础优化(一),布布扣,bubuko.com

centos基础优化(一)

标签:linux   centos   系统优化   

原文地址:http://stone880117.blog.51cto.com/1664014/1423764

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!