CentOS項目實例之一--操作系統安裝

  

1. Linux操作系統安裝

1.1. 最小化安裝

使用CentOS-7.0-1406-x86_64-DVD.iso來進行安裝

通過kickstart文件來簡化管理

http://172.16.1.100/7mini.txt(該IP爲測試環境中的服務器地址,這也是最小化安裝的格式)

# CentOS 7 64bit 用於生產環境的最小安裝 14:57 2014/9/27

# System authorization information

auth --enableshadow --passalgo=sha512


# Use CDROM installation media

cdrom

text

# Run the Setup Agent on first boot

firstboot --enable

ignoredisk --only-use=sda

# Keyboard layouts

keyboard --vckeymap=us --xlayouts='us'

# System language

lang en_US.UTF-8


# Network information

#network  --bootproto=dhcp --device=eno16777728 --onboot=no --ipv6=auto

network --onboot yes --device eno16777728 --bootproto dhcp --noipv6 

network  --hostname=localhost.localdomain

# Root password

rootpw 123456


firewall --disable 

selinux --disable 


# System timezone

timezone --utc Asia/Shanghai 

# System bootloader configuration

bootloader --location=mbr --boot-drive=sda

autopart --type=lvm

# Partition clearing information

clearpart --none --initlabel


reboot

%packages

@core

@base

net-tools

%end



1.2. 操作系統升級

查看當前版本信息

# uname -a
Linux localhost.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)

背景知識:yum -y upgrade 和 yum -y update 區別

YumMan幫助

update

              If run without any packages, update will update every  currently

              installed package.  If one or more packages or package globs are

              specified, Yum will only  update  the  listed  packages.   While

              updating  packages,  yum  will  ensure that all dependencies are

              satisfied. (See Specifying package names for  more  information)

              If  the  packages or globs specified match to packages which are

              not currently installed  then  update  will  not  install  them.

              update  operates  on  groups, files, provides and filelists just

              like the "install" command.


              If the main obsoletes configure option is true (default) or  the

              --obsoletes  flag  is present yum will include package obsoletes

              in its calculations - this makes it  better  for  distro-version

              changes,  for example: upgrading from somelinux 8.0 to somelinux

              9.


              Note that "update" works on installed packages first,  and  only

              if there are no matches does it look for available packages. The

              difference is most noticeable when you do "update foo-1-2" which

              will  act  exactly  as "update foo" if foo-1-2 is installed. You

              can use the "update-to" if you'd prefer that nothing  happen  in

              the above case.

upgrade

              Is the same as the update command with the --obsoletes flag set.

              See update for more details.


       yum -y update 

    升級所有包,改變軟件設置和系統設置,系統版本內核都升級

    

        yum -y upgrade

    升級所有包,不改變軟件設置和系統設置,系統版本升級,內核不改變


# yum -y upgrade

提示共升級35個包,包括kernel.x86_64 0:3.10.0-123.6.3.el7


重新啓動之後,進行驗證  

# uname -a
Linux localhost.localdomain 3.10.0-123.6.3.el7.x86_64 #1 SMP Wed Sep 6 21:12:36 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)

1.3. 主機名

CentOS 7中主機名的配置文件與Redhat相比發生了變化,不是在是/etc/sysconfig/network

更改/etc/hostname,纔會生效

# vi /etc/hostname
zzsrv1.bigcloud.local
# reboot


1.4. DNS服務器配置

除了傳統的修改/etc/resolv.conf之外,還有通過在ifcfg文件中添加配置的方式。

Tip: Windows在某個網卡中設置DNS服務器的IP地址類似


vi /etc/sysconfig/network-scripts/ifcfg-eno16777728

# Generated by parse-kickstart

IPV6INIT=no

BOOTPROTO=static

DEVICE=eno16777728

ONBOOT=yes

TYPE=Ethernet

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

IPV4_FAILURE_FATAL=no

NAME="System eno16777728"

IPADDR=192.168.188.11

NETMASK=255.255.255.0

GATEWAY=192.168.188.2

DNS1=192.168.188.11

DNS2=192.168.188.12


這樣,當重新啓動network服務時,會生成/etc/resolv.conf中的配置

# service network restart
Restarting network (via systemctl):                        [  OK  ]
# cat /etc/resolv.conf

# Generated by NetworkManager

search bigcloud.local

nameserver 192.168.188.11

nameserver 192.168.188.12


1.5. 雜項

1.5.1. 服務的控制


# chkconfig --list

Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration.


      If you want to list systemd services use 'systemctl list-unit-files'.

      To see services enabled on particular target use

      'systemctl list-dependencies [target]'.


iprdump         0:off   1:off   2:on    3:on    4:on    5:on    6:off

iprinit         0:off   1:off   2:on    3:on    4:on    5:on    6:off

iprupdate       0:off   1:off   2:on    3:on    4:on    5:on    6:off

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off

network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

vmware-tools    0:off   1:off   2:on    3:on    4:on    5:on    6:off

vmware-tools-thinprint  0:off   1:off   2:on    3:on    4:on    5:on    6:off


systemctl是系統服務管理器的命令,它將servicechkconfig這兩個命令組合在一起。


任務

舊指令

新指令

使某服務自動啓動

chkconfig --level 3 httpd on

systemctl enable httpd.service

使某服務不自動啓動

chkconfig --level 3 httpd off

systemctl disable httpd.service

檢查服務狀態

service httpd status

systemctl status httpd.service (服務詳細信息) systemctl is-active httpd.service (僅顯示是否 Active)

顯示所有已啓動的服務

chkconfig --list

systemctl list-units --type=service

啓動某服務

service httpd start

systemctl start httpd.service

停止某服務

service httpd stop

systemctl stop httpd.service

重啓某服務

service httpd restart

systemctl restart httpd.service


 

我在做這部分時,在修改主機名時,費了不少的功夫,一直按照Redhat的方式修改總是錯誤,最後上網查找資料,看了好幾篇文章,才最終改對了。服務啓動的方式也與原來不同。

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