centos7.0下载:

DVD ISO:  http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso

完整ISO: http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7.0-1406-x86_64-Everything.iso

官方网站:http://www.centos.org 

centos包:http://vault.centos.org/   或者  http://mirrors.oschina.net/centos/ 

centos7更多详情: http://wiki.centos.org/zh/Manuals/ReleaseNotes/CentOS7 

RedHat下载:https://access.redhat.com/downloads/ 

中国源: http://dragon.oschina.net 

中国源软件下载: http://dl.oschina.net 

centos几个新特性:

使用centos的官方yum源

yum clean all 

yum install net-tools

ifconfig命令在net-tools软件包里

nslookup,dig在bind-utils中

centos使用了systemd来代替sysvinit

systemd服务管理程序,它融合service和chkconfig功能于一体。你可以使用它永久或只在当前会话中启用/禁用服务。

systemctl (start|stop) httpd.service

systemctl (enable|disable) httpd.service

列出正在运行的服务或其他: systemctl

systemd-cgls以树形列出正在运行的进程。它可以递归显示给定控制组内容。

显示一个服务(无论运行与否)的状态: systemctl status httpd.service 

查看服务是否开机启动:systemctl is-enabled iptables.service;echo $?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
  
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/usr/sbin/httpd $OPTIONS -k graceful-stop
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

在sysvinit下,启动start、关闭stop、重启restart都是用$1来传递参数,但是在systemctl下,很是像supervisord这个daemon程序。

修改运行级别:

第 3 运行级用 multi-user.target替代。第 5 运行级用graphical.target替代。runlevel3.target 和 runlevel5.target 分别是指向 multi-user.target和graphical.target的符号链接。  

你可以使用下面的命令切换到“运行级 3 ”: 

systemctl isolate multi-user.target 或者

systemctl isolate runlevel3.target  

你也可以使用下面的命令切换到“运行级 5 ”: 

systemctl isolate graphical.target 或者

systemctl isolate runlevel5.target 

如何改变默认运行级别? 

systemd不使用/etc/inittab文件

systemd使用链接来指向默认的运行级别。在创建新的链接前,你可以通过下面命令删除存在的链接: rm /etc/systemd/system/default.target 

默认切换到运行级 3 : 

ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target 

默认切换到运行级 5 : 

ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target 

如何查看当下运行级别? 

runlevel命令在systemd下仍然可以工作。你可以继续使用它,尽管systemd使用 'target' 概念(多个的 'target' 可以同时激活)替换了之前系统的runlevel。

等价的systemd命令是 systemctl list-units --type=target

1
2
3
4
5
6
7
8
[ [email protected] ~]# chkconfig --list|grep samba      
  
注意:该输出结果只显示SysVinit服务,并不包含原生systemd服务。SysV配置数据可能被原生systemd配置覆盖。 
      如果您想列出systemd服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。
[ [email protected] ~]# systemctl list-dependencies samba 
samba.service

引导方式:使用grub2引导


RHEL7/CentOS7默认运行级别和终端分辨率

修改分辨率吧;

 在grub中我们修改的是/boot/grub/grub.conf,而在grub2中要修改的文件是/boot/grub2/grub.cfg;找到

1
linux16 /vmlinuz-3.10.0-123.el7.x86_64 root=UUID=881ac4e6-4a55-47b1-b864-555de7051763 ro rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto  vconsole.keymap=us rhgb quiet LANG=en_US.UTF-8

在后面添加vga=0x???(问号代表分辨率代码),在这里贴一张对应表,方便查看

wKioL1PTCmqDMcaoAARRmjQq9co274.jpg

修改后如下:wKioL1PTCwyiqV8vAAItWYMY-KU707.jpg

第二个是修改运行级别,大家都知道在grub中是修改/etc/inittab,将与之对应的数字修改就ok,但是在grub2中也变了,RHEL7使用systemd创建符号链接的方式指向默认运行级别,完了记得reboot下

1
# ln -sf /lib/systemd/system/runlevel?.target /etc/systemd/system/default.target[object Object]

例如我修改默认运行级别为字符终端,就是用命令:

1
# ln -sf /lib/systemd/system/runlevel13.target /etc/systemd/system/default.target


centos7.0安装成功后如何使用yum,ifconfig,pvcreate相关命令

我们安装时的文件是依照/root/anaconda-ks.cfg这个回答文件安装的,cat查看它

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[ [email protected] ~]# cat/root/anaconda-ks.cfg
#version=RHEL7
# System authorization information
auth --enableshadow --passalgo=sha512
   
# Use CDROM installation media
cdrom
# 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=eno16777736 --onboot=off --ipv6=auto
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted$6$ujXxVQ3lCFRecY/T$RyN0pe6ylmwQYiM3AFm0PAyP2E7yZ8MVZIAAGnVoRGJRcawrQYynAzQWd/dNvELy4LUUGb8kKEJ3GnKWSEs7..
# System timezone
timezone America/New_York --isUtc
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --none --initlabel
# Disk partitioning information
part / --fstype="xfs"--ondisk=sda --size=17407
part swap --fstype="swap"--ondisk=sda --size=1024
part /data --fstype="xfs" --ondisk=sda--size=2048
   
%packages
@core  #系统的核
   
%end

我们发现系统默认最小化安装有core没有base。而我们需要的那些基础的命令是打包在base内的,既然问题发现了,下面我们开始安装base。

在bash界面输入下面命令

1
2
3
4
5
6
7
8
9
10
11
[ [email protected] yum.repos.d]# vi CentOS-dvd.repo
[centos-dvd]
name=CentOS
baseurl=file:///mnt/disk/
enabled=1
gpgcheck=0
:x
[ [email protected] yum.repos.d]# ls
CentOS-Base.repo.bak       CentOS-dvd.repo          CentOS-Vault.repo.bak
CentOS-Debuginfo.repo.bak  CentOS-Sources.repo.bak
#为了方便我们yum.repos.d下以repo的文件都改为bak的后缀,之后新添加CentOS-dvd.repo文件并设置相关路径其他四个文件的具体内容可自行百度

修改完毕输入下面命令

#yum groupinstall base
#下面会出现172个需要安装的包,y即可

显示Complete后,yum,ifconfig,pvcreate等命令都可正常使用。


一:设置IP地址、网关DNS,路由,iP命令,网络管理工具

在安装的时候选择mini安装类型,可能导致有些基础包没有被安装上,

yum -y groupinstall Base

通过上面命令可以将一些基础包安装,正常使用 ifconfig | lsof命令。

说明:RHEL 7.0默认安装好之后是没有自动开启网络连接的!

cd  /etc/sysconfig/network-scripts/  #进入网络配置文件目录

      vi  ifcfg-eno16777736  #编辑配置文件,添加修改以下内容

TYPE="Ethernet|Bridge"网络接口类型

BOOTPROTO="static"  #启用静态IP地址

DEFROUTE="yes"

IPV4_FAILURE_FATAL="no"

IPV6INIT="yes|no"  是否支持IPV6

USERCTL="yes|no"   是否允许普通用控制此接口

PEERDNS="yes|no"   是不是接受DHCP服务器指派的DNS服务器地址

IPV6_AUTOCONF="yes"

IPV6_DEFROUTE="yes"

IPV6_FAILURE_FATAL="no"

NAME="eno16777736"

UUID="8071cc7b-d407-4dea-a41e-16f7d2e75ee9"  设备标识号

ONBOOT="yes"  #开启自动启用网络连接

IPADDR0="192.168.21.128"  #设置IP地址   只有在BOOTPROTO={none|static}设置才有效

PREFIX0="24"  #设置子网掩码   此设置也可用 PREFIX=n (n为掩码位数)

GATEWAY0="192.168.21.2"  #设置网关      要与IP地址属于同一网段

DNS1="8.8.8.8"  #设置主DNS

DNS2="8.8.4.4"  #设置备DNS

HWADDR="00:0C:29:EB:F2:B3"

IPV6_PEERDNS="yes"

IPV6_PEERROUTES="yes"

service network restart   #重启网络

CentOS 7下网卡重新命名

在CentOS5的时候,我们使用eth0方式网络设备命名,在CentOS 6下,网络设备变成了em1 的命名。但在安装的时候,给启动参数加上 biosdevname=0,就可以继续使用 eth0 这样的命名。新装的CentOS 7网卡命名已经默认不像之前的那样了,原有的参数biosdevname=0不起作用了。如果你希望继续使用 eth0 这样的传统名称,那么在安装启动时加上参数:

et.ifnames=0 biosdevname=0

如果你已经安装完了,希望改成eth0这样的名称,那么需要:

编辑/etc/sysconfig/grub文件内容

下边是编辑前的文件内容:

wKioL1PNzOHBrVV5AAEnHbxb9Ug004.jpg

增加“net.ifnames=0 biosdevname=0”,编辑后的文件内容:

GRUB_CMDLINE_LINUX=”rd.lvm.lv=vg0/swap vconsole.keymap=us crashkernel=auto  vconsole.font=latarcyrheb-sun16 net.ifnames=0 biosdevname=0 rd.lvm.lv=vg0/usr rhgb quiet”

wKioL1PN0CegVKztAAEp3_d9yjs335.jpg

执行:grub2-mkconfig -o /boot/grub2/grub.cfg

重新对网卡配置文件进行命名:

/etc/sysconfig/network-scripts/ifcfg-*

wKioL1PN1F6yo7nDAAHNfH4ameQ933.jpg

然后重启系统后查看网卡名称:

wKioL1PNzQWxcsfOAAJUNRImCoo148.jpg

CentOS 7是由于systemd 和 udev 引入了一种新的网络设备命名方式:一致网络设备命名(CONSISTENT NETWORK DEVICE NAMING) 。可以根据固件、拓扑、位置信息来设置固定名字,带来的好处是命名自动化,名字完全可预测,在硬件坏了以后更换也不会影响设备的命名,这样可以让硬件的更换无缝化。带来的不利是新的设备名称比传统的名称难以阅读。

参考:http://www.pubyun.com/blog/deveops/centos-7%E4%B8%8B%E7%BD%91%E7%BB%9C%E8%AE%BE%E5%A4%87%E5%91%BD%E5%90%8D/ 

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/ch-Consistent_Network_Device_Naming.html   RHEL7网络指南

https://bugzilla.redhat.com/show_bug.cgi?id=965718       红帽子BUG965718

ping www.baidu.com  #测试网络是否正常

traceroute 和 mtr 显示出我们到达一个网络所经过的路由信息

yum -y install traceroute

yum -y install mtr

wKiom1PIzAHj4h7cAAF9ieppR_k702.jpg

1
 [ [email protected] ~]# mtr -n

wKiom1PIzf7BIE23AADuxz_d1uA968.jpgethtool:查看网路接口设备本身的属性wKioL1PGiJzD4lWfAAIaN8RQU2U692.jpg

设置路由信息

临时生效:

route -n 以数字形式显示路由表

ip route list

  增加一条主机路由

  [[email protected] ~]# route add -host 172.16.9.18 gw 172.16.0.1 dev eth0


  增加一条网络路由

  [[email protected] ~]# route add -net 10.0.0.0/8 gw 172.16.0.1 dev eth0 设置默认路由

  #route add default gw NEXT_HOP
  删除主机路由和网络路由
  [ [email protected] ~]# route del -net 10.0.0.0/8  dev eth0
  [ [email protected] ~]# route del -host 172.16.9.18  dev eth0


   永久生效:

    配置文件在/etc/sysconfig/network-scripts/ 目录下:

每个网卡路由对应一个配置文件(包括网卡别名的)route-IFNAME。例如:eth0网卡的配置路由文件是 route-eth0。设置格式1:每一行一个路由条目   DESTINATION via NETX_HOP

192.168.0.0/24 via 172.16.0.1

设置格式2:每3行一个路由条目  

        ADDRESS#=DESTINATION

        NETMASK#=MASK

        GATEWAY#=GW

# 要是设置主机路由的话,掩码位数是32位
ADDRESS0=192.168.0.0
NETMASK0=255.255.0.0
GATEWAY=172.16.0.1


iP命令常用选项

ip link : 管理接口

        show [IFNAME]

        set IFNAME {up|down}

1
2
3
4
5
6
7
8
9
10
[ [email protected] ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:e0:db:d8 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:e0:db:e2 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:e0:db:ec brd ff:ff:ff:ff:ff:ff
[ [email protected] ~]# ip link set eth2 down

ip addr: 管理协议地址

 ip addr {show|flush} [dev DEVICE] 查看网卡的IP地址

 ip addr {add|del} ADDRESS dev DEVICE [label IFALIAS] [broadcast BCAST_ADDRESS],为一个网卡添加多个IP

1
2
3
4
5
6
7
8
9
10
11
[ [email protected] ~]# ip addr show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:e0:db:e2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.4/24 brd 192.168.1.255 scope global eth1
    inet6 fe80::20c:29ff:fee0:dbe2/64 scope link 
       valid_lft forever preferred_lft forever
[ [email protected] ~]# ip addr add 192.168.0.23/24 dev eth2 label eth2:0
[ [email protected] ~]# ifconfig eth2:0
eth2:0    Link encap:Ethernet  HWaddr 00:0C:29:E0:DB:EC  
          inet addr:192.168.0.23  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

二:使用系统镜像文件配置本地yum源

       1.上传系统镜像文件rhel-server-7.0-x86_64-dvd.iso到/usr/local/src目录

2.挂载系统镜像文件

mkdir /media/cdrom  #新建镜像文件挂载目录

cd /usr/local/src  #进入系统镜像文件存放目录

mount -t iso9660 -o loop /usr/local/src/rhel-server-7.0-x86_64-dvd.iso  /media/cdrom #挂载系统镜像

备注:umount  /media/cdrom  #卸载系统镜像

3.设置开机自动挂载系统镜像文件

vi /etc/fstab   #添加以下代码。实现开机自动挂载

/usr/local/src/rhel-server-7.0-x86_64-dvd.iso  /media/cdrom   iso9660    defaults,ro,loop  0 0

备注:iso9660使用df  -T 查看设备

4.配置本地yum源

cd /etc/yum.repos.d/   #进入yum配置目录

touch  rhel-media.repo   #建立yum配置文件

cat rhel-media.repo   #编辑配置文件,添加以下内容

[rhel-media]

name=Red Hat Enterprise Linux 7.0   #自定义名称

baseurl=file:///media/cdrom #本地光盘挂载路径

enabled=1   #启用yum源,0为不启用,1为启用

gpgcheck=1  #检查GPG-KEY,0为不检查,1为检查

gpgkey=file:///media/cdrom/RPM-GPG-KEY-redhat-release   #GPG-KEY路径

5.使用yum命令自动安装软件

yum clean all   #清除yum缓存

yum makecache  #缓存本地yum源中的软件包信息

yum install httpd   #安装apache

rpm -ql httpd  #查询所有安装httpd的目录和文件

systemctl start/stop/restart httpd.service  #启动/停止/重启apache

systemctl enable httpd.service  #设置开机启动

6.RHEL 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙

关闭firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

yum install iptables-services  #安装iptables

vi /etc/sysconfig/iptables  #编辑防火墙配置文件

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

:wq! #保存退出

systemctl  start/stop/restart/status  iptables.service  #启动/停止/重启防火墙,查看防火墙状态

systemctl  enable  iptables.service  #设置开机启动

6.设置主机名为www

hostname  www  #设置主机名为www

vi /etc/hostname #编辑配置文件

www   localhost.localdomain  #修改localhost.localdomain为www

vi /etc/hosts #编辑配置文件

127.0.0.1  www localhost  #修改localhost.localdomain为www

shutdown -r now  #重启系统

三:安装配置LAMP服务器(Apache+PHP+MariaDB)

1、安装Apache

yum install httpd #根据提示,输入Y安装即可成功安装

2.安装MariaDB

RHEL 7.0中,已经使用MariaDB替代了MySQL数据库

yum install mariadb mariadb-server #询问是否要安装,输入Y即可自动安装,直到安装完成

systemctl start/STOP/RESTART mariadb.service #启动/停止/重启MariaDB

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷贝配置文件(如果/etc目录下面默认有一个my.cnf,直接覆盖即可)

为root账户设置密码

mysql_secure_installation

回车,根据提示输入Y

输入2次密码,回车

根据提示一路输入Y

最后出现:Thanks for using MariaDB!

3.安装PHP

yum install php #根据提示输入Y直到安装完成

安装PHP组件,使PHP支持 MariaDB

yum install php-mysql php-gd libjpeg*  php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash

#这里选择以上安装包进行安装,根据提示输入Y回车

     4.进行相关配置

一、Apache配置

vi /etc/httpd/conf/httpd.conf #编辑文件

ServerSignature On #添加,在错误页中显示Apache的版本,Off为不显示

Options Indexes FollowSymLinks #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)

#AddHandler cgi-script .cgi #修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)

AllowOverride None  #修改为:AllowOverride All (允许.htaccess)

AddDefaultCharset UTF-8 #修改为:AddDefaultCharset GB2312 (添加GB2312为默认编码)

#Options Indexes FollowSymLinks  #修改为 Options FollowSymLinks(不在浏览器上显示树状目录结构)

DirectoryIndex index.html  #修改为:DirectoryIndex index.html index.htm Default.html Default.htm index.php(设置默认首页文件,增加index.php)  

MaxKeepAliveRequests 500 #添加MaxKeepAliveRequests 500 (增加同时连接数)

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #删除默认测试页

二、php配置

vi /etc/php.ini #编辑

date.timezone = PRC #把前面的分号去掉,改为date.timezone = PRC

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

expose_php = Off #禁止显示php版本的信息

magic_quotes_gpc = On #打开magic_quotes_gpc来防止SQL注入

short_open_tag = ON #支持php短标签

open_basedir = .:/tmp/  #设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php***跨站,如果改了之后安装程序有问题,可以注销此行,或者直接写上程序的目录/data/www.test.com/:/tmp/

最后进行页面访问测试:

cd /var/www/html

vi index.php #输入下面内容

<?php

phpinfo();

?>

在客户端浏览器输入服务器IP地址,可以看到如下图所示相关的配置信息!

如果页面打不开,请确保firewalld防火墙已经关闭

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

注意:apache默认的程序目录是/var/www/html

权限设置:chown apache.apache -R /var/www/html

本文出自 “从心开始” 博客,请务必保留此出处http://hao360.blog.51cto.com/5820068/1438383