初识CentOS服务命令大全

分类:CentOS教程 阅读:48883 次

(1)系统架构

查看内核
  1. #uname-s-r
  2. Linux2.6.32-358.el6.x86_64


查看发布版本
  1. #cat/etc/redhat-release
  2. CentOSrelease6.4(Final)


查看CPU架构
  1. #arch
  2. x86_64(x86_64表示64位机器/i686表示32位机器)
  3. #getconfLONG_BIT
  4. 64


(2)用户设置

添加用户
  1. #/usr/sbin/useradduser1-d/home/user1-Gnobody
  2. #passwduser1
  3. Newpassword:123456
  4. Retypenewpassword:123456
  5. passwd:allauthenticationtokensupdatedsuccessfully.


确认用户
  1. #iduser1


删除用户
  1. #userdel-ruser1


赋予root权限
  1. #usermod-Gwheelhoge
  2. #vi/etc/pam.d/su
  3. authrequiredpam_wheel.souse_uid#<=取消注释


用户一览
  1. #cat/etc/passwd


(3)网络设置

设置IP
  1. #vi/etc/sysconfig/network-scripts/ifcfg-eth0
  2. DEVICE="eth0"
  3. OTPROTO="static"#<=
  4. HWADDR="00:0C:29:53:A5:AE"
  5. IPV6INIT="no"#<=
  6. NM_CONTROLLED="yes"
  7. ONBOOT="yes"
  8. TYPE="Ethernet"
  9. UUID="1ca6acf4-ebce-415a-a89b-bf89a67819ff"
  10. IPADDR="xxx.xxx.xx.xx"#<=
  11. NETMASK="255.255.255.0"#<=
  12. GATEWAY="xxx.xxx.xx.xx"#<=
  13. DNS1="xxx.xxx.xx.xx"#<=
  14. #servicenetworkrestart
  15. Shuttingdowninterfaceeth0:
  16. ......
  17. Connectionactivated[OK]
  18. #ifconfig
  19. eth0Linkencap:EthernetHWaddr00:0C:29:2F:D5:58
  20. inetaddr:xxx.xxx.xx.xxBcast:xxx.xxx.xx.xxMask:255.255.255.0
  21. ......


卸载NestworkManager服务
  1. #chkconfigNetworkManageroff
  2. #yum-yremoveNetworkManager


关闭IPv6
  1. #serviceip6tablesstop
  2. #chkconfigip6tablesoff
  3. #echo"installipv6/bin/true">>/etc/modprobe.d/disable-ipv6.conf
  4. #vi/etc/sysconfig/network
  5. NETWORKING_IPV6=no
  6. IPV6INIT=no
  7. #vi/etc/sysconfig/network-scripts/ifcfg-eth0
  8. #shutdown-rnow
  9. #lsmod|grepipv6
  10. 没有ipv6模块
  11. #netstat-an|grepffff
  12. 没有:ffff:开始的IP
  13. #ifconfig
  14. 没有inet6addr开始的文字


(4)包管理设置

yum清理
  1. #yumcleanall
  2. Loadedplugins:fastestmirror,security
  3. Cleaningrepos:baseextrasupdates
  4. CleaningupEverything
  5. #yummakecache
  6. Loadedplugins:fastestmirror,security
  7. Determiningfastestmirrors
  8. ………….
  9. MetadataCacheCreated


yum更新
  1. #yum-yupdate


自动更新
  1. #yum-yinstallyum-cron
  2. #vi/etc/sysconfig/yum-cron
  3. CHECK_ONLY=yes
  4. DOWNLOAD_ONLY=yes
  5. #/etc/rc.d/init.d/yum-cronstart
  6. #chkconfigyum-cronon
  7. #chkconfig--listyum-cron


自动查找最快镜像
  1. #yum-yinstallyum-plugin-fastestmirror
  2. #vi/etc/yum/pluginconf.d/fastestmirror.conf
  3. enabled=0←0:无效1:有效


添加repository
  1. #vi/etc/yum.repos.d/CentOS-Base.repo
  2. #rpm-Uvhhttp://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  3. #vi/etc/yum.repos.d/rpmforge.repo
  4. enabled=0
  5. #yum--enablerepo=rpmforgeinstallxxxx
  6. #rpm-Uvhhttp://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
  7. #vi/etc/yum.repos.d/epel.repo
  8. enabled=0
  9. #yum--enablerepo=epelinstallxxxx


(5)设置vim
  1. #yum-yinstallvim-enhanced
  2. #vi/etc/profile
  3. aliasvi='vim'
  4. #source/etc/profile
  5. #vi/etc/vimrc


(6)安全设置

关闭SELinux
  1. #getenforce
  2. #setenforce0←临时关闭
  3. #vi/etc/sysconfig/selinux
  4. SELINUX=enforcing
  5.    ↓
  6. SELINUX=disabled


停止iptables
  1. #/etc/rc.d/init.d/iptablesstop
  2. iptables:Flushingfirewallrules:[OK]
  3. iptables:SettingchainstopolicyACCEPT:filter[OK]
  4. iptables:Unloadingmodules:[OK]
  5. #chkconfigiptablesoff
  6. #chkconfig--listiptables
  7. iptables0:off1:off2:off3:off4:off5:off6:off


(7)系统运行情况

磁盘使用情况
  1. #df-h
  2. #yum-yinstallsysstat
  3. #iostat


内存使用情况
  1. #free-m


CPU和内存
  1. #cat/proc/cpuinfo
  2. #cat/proc/meminfo


(8)其他

本地语言化
  1. #yum-ygroupinstall"JapaneseSupport"
  2. #vi/etc/sysconfig/i18n
  3. LANG="en_US.UTF-8"
  4.    ↓
  5. LANG="ja_JP.UTF-8"
  6. #source/etc/sysconfig/i18n
  7. #echo$LANG
  8. ja_JP.UTF-8
  9. #shutdown-rnow


停止不必要的服务
  1. #chkconfig--list|grep3:on
  2. #serviceip6tablesstop
  3. #chkconfigip6tablesoff


编码转换nkf(Network Kanji Filter)
  1. #yum-yinstallnkf
  2. #vireadme.txt
  3. test
  4. ?h字
  5. #nkf-greadme.txt
  6. UTF-8(LF)
  7. #nkf-s--overwritereadme.txt
  8. #nkf-greadme.txt
  9. Shift_JIS(LF)
  10. #nkf-j--overwritereadme.txt
  11. #nkf-greadme.txt
  12. ISO-2022-JP(LF)


安装gcc
  1. #rpm-qagcc
  2. #yum-yinstallgccgcc-c++
  3. #gcc-v
  4. Usingbuilt-inspecs.
  5. Target:i686-redhat-linux
  6. …………
  7. gccversion4.4.720120313(RedHat4.4.7-4)(GCC)


安装PCRE
  1. #cd/usr/local/src
  2. #wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
  3. #tarzxvfpcre-8.35.tar.gz
  4. #cd/usr/local/src/pcre-8.35
  5. #./configure--prefix=/usr/local/pcre/8.35
  6. #makeclean
  7. #make&&makeinstall
  8. #PATH=/usr/local/pcre/8.35/bin:$PATH
  9. #vi/etc/ld.so.conf
  10. /usr/local/pcre/8.35/lib←末尾追加
  11. #ldconfig
  12. #rpm-qapcre
  13. pcre-7.8-6.el6.x86_64
  14. #pcretest-C
  15. PCREversion7.82008-09-05


安装OpenSSL
  1. #cd/usr/local/src
  2. #wgethttp://www.openssl.org/source/openssl-1.0.1h.tar.gz
  3. #tarxzvfopenssl-1.0.1h.tar.gz
  4. #cdopenssl-1.0.1h
  5. #./configshared-fPIC
  6. #make&&makeinstall
  7. #vi/etc/ld.so.conf
  8. /usr/local/ssl/lib←末尾追加
  9. #ldconfig
  10. #ldconfig-f/etc/ld.so.conf-vp|grepssl/lib
  11. libssl.so.1.0.0(libc6)=>/usr/local/ssl/lib/libssl.so.1.0.0
  12. libssl.so(libc6)=>/usr/local/ssl/lib/libssl.so
  13. libcrypto.so.1.0.0(libc6)=>/usr/local/ssl/lib/libcrypto.so.1.0.0
  14. libcrypto.so(libc6)=>/usr/local/ssl/lib/libcrypto.so
  15. #/usr/local/ssl/bin/opensslversion
  16. OpenSSL1.0.1h5Jun2014


NTP同步时间
  1. #yumupdateglibc
  2. #rpm-qa|grepglibc
  3. 2.12-1.149.el6_6.5