服务管理
- ntp/chrony
- sshd
- nfs
- vsftpd
- dns
- apache
时间服务器-NTP/chrony
NTP: Network Time Protocol
协议端口:
tcp/123
udp/123
主配置文件: /etc/ntp.conf
服务器:192.168.10.11
客户端:192.168.10.12
服务器端:
1.安装软件
# yum install ntp -y
2.配置
# vim /etc/ntp.conf
server 127.127.1.0 #添加上这行,将本机作为本地时间服务器
3.启动服务
# systemctl start ntpd #启动服务
# systemctl enable ntpd #开机启动
4.查看服务运行情况
# ntpq -p
remote refid st t when poll reach delay offset jitter
==========================================================
*LOCAL(0) .LOCL. 5 l 35 64 7 0.000 0.000 0.000
客户端:
1.安装软件
# yum install ntpdate -y
2.同步时间
# ntpdate 192.168.10.11
要实现自动同步,可结合计划任务来实现
=============================================
chrony
软件名:chrony #服务器和客户端都安装
服务名:chronyd
配置文件: /etc/chrony.conf
服务器配置:
[root@server ~]# vim /etc/chrony.conf
# Allow NTP client access from local network.
allow 192.168.132.0/24 #允许哪些客户端同步时间
[root@server ~]# systemctl start chronyd #启动服务
[root@server ~]# systemctl enable chronyd #设置为开机启动
[root@server ~]# chronyc sources #查看服务器资源状态
客户端:
[root@client ~]# vim /etc/chrony.conf
[root@client ~]# systemctl start chronyd #启动服务
[root@client ~]# systemctl enable chronyd #设置为开机启动:
[root@server ~]# chronyc sources
crontab -e
*/3 * * * * /usr/sbin/ntpdate ntp.aliyun.com
远程连接服务-SSH
SSH详解
sshd服务
服务的软件包 openssh-server
服务名称: sshd
ssh ---Secure SHell 安全shell连接
功能:实现加密方式的远程连接
ssh远程连接的软件(客户端软件)
linux:openssh-clients
windows:xmanager Xshell putty SecureCrt
默认端口及协议
tcp/udp 22
环境:
server 192.168.1.251 server.qf.com
client 192.168.1.250 client.qf.com
一般情况下,安装操作系统时默认就安装了ssh。
一、查看软件包是否安装
# rpm -qa | grep openssh
openssh-server-6.6.1p1-31.el7.x86_64 #服务器端软件包
openssh-clients-6.6.1p1-31.el7.x86_64 #客户端软件包
二、服务器端的配置文件
# vim /etc/ssh/sshd_config
17 #Port 22 #默认端口22
18 #AddressFamily any #支持任意地址簇(ipv4/ipv6)
19 #ListenAddress 0.0.0.0 #监听在任何ipv4地址上
20 #ListenAddress :: #监听在任何ipv6地址上
23 #Protocol 2 #协议版本
43 SyslogFacility AUTHPRIV #定义日志的对象
44 #LogLevel INFO #定义日志的级别
48 #LoginGraceTime 2m #连接2分钟不输入密码就断开
49 #PermitRootLogin yes #允许管理员root登陆
50 #StrictModes yes #用严格模式
51 #MaxAuthTries 6 #最大尝试6次
52 #MaxSessions 10 #允许最大会话10个
78 #PermitEmptyPasswords no #密码为空不能登陆
79 PasswordAuthentication yes #是否采用密码认证 no为不能输入密码
115 X11Forwarding yes #开启x11转发协议
127 #ClientAliveCountMax 3 #客户端连接服务器输入密码尝试的次数
129 #UseDNS yes #采用dns解析,默认打开,注释也没用,故设置为UseDNS no
130 #PidFile /var/run/sshd.pid #pid文件位置
查看网络连接状况:
[root@server .ssh]# netstat -tuanp |grep sshd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 32057/sshd
-a (all)显示所有选项
-t tcp协议
-u udp协议
-l listening
-n 以数字方式显示,不解析
-p 进程名
[root@server .ssh]# lsof -i:22
有返回内容表示服务处于监听状态
ssh的基本使用
ssh的基本使用
守护进程:sshd
# systemctl start sshd
# systemctl restart sshd
# systemctl status sshd 查看服务的状态
远程登陆
指定用户身份的远程登陆
不登陆远程执行命令
远程拷贝
1、远程登陆
[root@localhost ~]# ssh 192.168.1.250
The authenticity of host '192.168.1.250 (192.168.1.250)' can't be established.
ECDSA key fingerprint is 34:e5:01:71:33:ef:76:42:12:da:aa:f9:d2:d8:d3:96.
Are you sure you want to continue connecting (yes/no)? yes #表示是第一次连接该主机,会问你是否保存指纹信息
Warning: Permanently added '192.168.1.250' (ECDSA) to the list of known hosts.
root@192.168.1.250's password: #需要输入远程主机的密码
1)退出远程登陆
[root@server ~]# exit
2)已知主机列表文件------指纹存放的文件
[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ls
known_hosts
文件是~/.ssh/known_hosts
如果遇到以下错误的话:是由于指纹信息对不上导致的
[root@localhost .ssh]# ssh 192.168.1.250
key_from_blob: remaining bytes in key blob 108
key_read: type mismatch: encoding error
key_from_blob: remaining bytes in key blob 108
key_read: type mismatch: encoding error
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
62:4c:4d:13:e9:a2:7d:cc:a8:0a:43:0d:12:9c:c0:ae.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:2
ECDSA host key for 192.168.1.250 has changed and you have requested strict checking.
Host key verification failed.
如何解决上述错误:(二选一即可)
a)删除known_hosts文件中与该ip相对应的行
b)清空known_hosts文件
[root@localhost .ssh]# > known_hosts
2、指定用户身份登陆
前提:远程主机上需要存在该用户
1)在远程主机上添加一个用户,并设置密码----192.168.1.250
[root@server ~]# useradd jim
[root@server ~]# echo "jim" | passwd --stdin jim
更改用户 jim 的密码 。
passwd:所有的身份验证令牌已经成功更新。
2)连接-------192.168.1.250
[root@localhost ~]# ssh jim@192.168.1.250
jim@192.168.1.250's password:jim
Last login: Fri Jun 30 14:43:07 2017
[jim@server ~]$ exit
登出
Connection to 192.168.1.250 closed.
3、不登陆远程执行命令
[root@localhost ~]# date ; ssh 192.168.1.250 date
2017年 07月 12日 星期三 13:01:26 CST
[root@192.168.1.250's password:
2017年 07月 12日 星期三 11:36:25 CST
[root@localhost ~]# ssh 192.168.1.250 reboot
4、图形化ssh连接 -X
# ssh 192.168.1.250 xeyes #打不开
root@192.168.1.250's password:
Error: Can't open display:
[root@localhost ~]# ssh -X 192.168.1.250 xeyes
root@192.168.1.250's password:
能够打开远程主机上xeyes程序
5、远程拷贝
scp [-r] 源 目的
1)本地文件拷贝给远程主机 上传
[root@localhost ~]# echo 192.168.1.251 > /tmp/test.txt
[root@localhost ~]# cat /tmp/test.txt
192.168.1.251
[root@localhost ~]# scp /tmp/test.txt 192.168.1.250:/root/desktop/
root@192.168.1.250's password:
test.txt 100% 14 0.0KB/s 00:00
2)远程主机文件拷贝到本地 下载
[root@localhost ~]# scp 192.168.1.250:/root/desktop/dianming.sh /tmp
root@192.168.1.250's password:
dianming 100% 150 0.2KB/s 00:00
[root@localhost ~]# ls /tmp/dianming.sh
/tmp/dianming.sh
常用选项:
-r 拷贝目录
-P port:指定端口,非22端口时必须要接此选项指定端口
更改端口设置
[root@server ~]# vim /etc/ssh/sshd_config
Port 2000
[root@server ~]# systemctl reload sshd
[root@server ~]# netstat -tulnp | grep sshd
tcp 0 0 0.0.0.0:2000 0.0.0.0:* LISTEN 27227/sshd
tcp6 0 0 :::2000 :::* LISTEN 27227/sshd
指定端口登陆
[root@localhost ~]# ssh -p 2000 192.168.1.250
ssh基于密钥的连接
基于密钥的连接:实现的是不输入密码登陆远程主机
是相对于用户来说的,不需要输入密码的
ssh采用的是基于公钥和私钥的加密技术进行自动化认证。
如果客户端连接服务器无密码。客户端上需要生成一对密钥,公钥传给服务器,那么服务器收到公钥,客户端连接服务器就不需要密码。
客户端配置
1.生成密钥
[root@localhost ~]# ssh-keygen
密钥位置
[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ls
id_rsa id_rsa.pub known_hosts
id_rsa 私钥
id_rsa.pub 公钥
known_hosts 已知主机,存指纹的文件
2.发送公钥给服务器
[root@localhost .ssh]# ssh-copy-id -i 192.168.1.250
3.测试客户端连接服务器不需要密码
[root@localhost .ssh]# ssh 192.168.1.250
Last login: Wed Jul 12 14:29:27 2017 from 192.168.1.251
[root@server ~]# exit
登出
Connection to 192.168.1.250 closed.
服务器会将客户端的公钥保存在authorized_keys 文件中
[root@server ~]# cd /root/.ssh/
[root@server .ssh]# ls
authorized_keys known_hosts
常见错误:
1.ssh连接出错
检测是否有ip地址
检测服务器和客户端是否能ping通
检测网卡连接方法
2.做双机互信。连接仍然还有密码
服务端
# 清空此authorized_keys文件内容
客户端
# ssh-add 密钥传送失败用此命令
# cd /root/.ssh
# rm -rf id*
# 重新做密钥重新发送
3.指纹验证不正确
删除known_hosts文件中对应的ip的指纹
访问控制
凡是支持tcpwrapper的都可以使用以下两个文件做访问控制:
/etc/hosts.allow
/etc/hosts.deny
# ldd `which sshd`|grep wrap
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f598bc08000)
先看allow,如果有,直接放行;
如果没有,再看deny,如果有,则拒绝,如果没有,则放行
例: 只允许192.168.1.250连接
# cat /etc/hosts.allow
sshd:192.168.1.250
# cat /etc/hosts.deny
sshd:* # *表示所有. 还可以写网段,如:192.168.1.0/24
两个都没有,默认放行
网络文件系统 - NFS
NFS部署实战
NFS -------Network File System 网络文件系统
samba ---- cifs
数据落地层
功能
unix/linux和linux之间文件共享
优点:是局域网共享中速度最快的
缺点:不支持跨平台
需要注意的问题:
1.需要依赖rpcbind
2.权限问题
3.对于已经在运行的nfs服务器,不要restart,用reload
什么是网络文件系统?
网络文件系统是一种将远程主机上的目录经过网络挂载到客户端本地系统的一种机制。
环境:
server 192.168.1.252 test1.qf.com
client 192.168.1.251 client.qf.com
一、查看软件包是否安装
# rpm -qa | grep nfs
nfs-utils-1.3.0-0.33.el7.x86_64 主程序包
# yum install nfs-utils -y
服务器端:
二、服务端配置要共享的资源
例:服务器共享/test目录,
[root@test1 ~]# mkdir /test
[root@test1 ~]# cd /test
[root@test1 test]# echo "nfs test" > test.txt
三、配置共享/test目录
1)配置以只读方式共享
[root@test1 ~]# vim /etc/exports
# man 5 exports
共享资源 共享给谁(共享的属性)
/test 192.168.1.251(rw,sync,no_root_squash)
#(如果还是报错无权限,加上no_root_squash选项)
四、启动服务
[root@test1 ~]# systemctl start nfs #el6要先启rpcbind
五、查看共享资源
[root@test1 ~]# showmount -e 192.168.1.252
Export list for 192.168.1.252:
/test 192.168.1.251
客户端:
六、查看共享资源 #el6要先启动rpcbind才能使用
[root@client ~]# showmount -e 192.168.1.252
Export list for 192.168.1.252:
/test 192.168.1.251
七、挂载
语法:mount.nfs 服务器地址:服务器共享的目录 本地的挂载点
[root@client ~]# mount.nfs 192.168.1.252:/test /opt
[root@client ~]# vim /etc/fstab #可选: 开机挂载
192.168.1.252:/test /opt nfs defaults 0 0
八、查看是否挂载
[root@client ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 17G 3.5G 14G 21% /
devtmpfs 473M 0 473M 0% /dev
tmpfs 489M 144K 489M 1% /dev/shm
tmpfs 489M 7.0M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 155M 860M 16% /boot
tmpfs 98M 16K 98M 1% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /run/media/root/CentOS 7 x86_64
192.168.1.252:/test 2.8G 33M 2.8G 2% /opt
九、测试
[root@client ~]# cd /opt
[root@client opt]# cat test.txt
nfs test
配置/etc/exports
# vim /etc/exports
共享资源 共享给谁(共享的属性)
# man 5 exports
共享资源:服务器的目录
共享给谁:多个主机 之间有空格隔开
192.168.1.251 某台主机
192.168.1.0/24
192.168.1.0/255.255.255.0
desk.qf.com 主机名
*.qf.com 匹配qf.com的所有主机
* 表示任意
共享的属性:文件系统的属性
ro 只读
rw 可读写
async 异步
sync 同步
secure 小于1024端口连接
insecure 大于1024端口连接
root_squash 把客户端使用root操作的文件的uid和gid映射为匿名用户(nfsnobody)
no_root_squash 不映射,以管理员root身份操作
all_squash 把所有用户创建文件的uid和gid都映射为匿名用户 (nfsnobody)
客户端权限问题
1.文件系统级别: 服务器共享的属性
ro: 只读
rw: 读写
2.基本UGO权限
默认情况下,客户端上的root用户会被映射为nfsnobody用户
如果服务器上的nfsnobody用户对共享目录有写权限,客户端的root用户才有写权限
解决客户端写权限问题:
1).在服务器上给共享目录加上写权限给nfsnobody,目录内的文件也同样需要授权给nfsnobody
2).在共享时加上no_root_squash属性
WEB服务 - Apache
apache安装 / 详解
apache是世界使用排名第一的web服务器软件。
官网:www.apache.org httpd.apache.org
优点:开源,支持二次开发,稳定好,支持多种操作系统,支持多种编程语言 (php ,html ,jsp,asp)
环境:
服务器:
192.168.1.252 www.qf.com
搭建
1.安装软件包
[root@www ~]# yum install httpd -y
[root@www ~]# rpm -ql httpd
/etc/httpd 配置文件目录
/etc/httpd/conf 主配置文件目录
/etc/httpd/conf.d 辅助配置文件目录
/etc/httpd/conf.d/README
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf 主配置文件
/etc/httpd/logs 日志目录
/etc/httpd/modules 模块目录
/etc/httpd/run 运行时的进程文件路径
/usr/sbin/httpd
/usr/share/doc/httpd-2.4.6 帮助文档
/usr/share/doc/httpd-2.4.6/httpd-default.conf
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
/var/www/html 主文档目录,默认网页发布目录
/var/log/httpd 日志
192.168.1.250/a.html
url 统一资源定位符 协议://主机/路径
2.启动服务
[root@www ~]# systemctl start httpd
客户端访问
http://192.168.1.252
-----------------------------搭建基本web站点---------------
[root@www ~]# cd /var/www/html/
[root@www html]# echo "hello apache" > index.html
客户端:
[root@client ~]# firefox http://192.168.1.252 &apache apache是世界使用排名第一的web服务器软件。
官网:www.apache.org httpd.apache.org
优点:开源,支持二次开发,稳定好,支持多种操作系统,支持多种编程语言 (php ,html ,jsp,asp)
环境:
服务器:
192.168.1.252 www.qf.com
搭建
1.安装软件包
[root@www ~]# yum install httpd -y
[root@www ~]# rpm -ql httpd
/etc/httpd 配置文件目录
/etc/httpd/conf 主配置文件目录
/etc/httpd/conf.d 辅助配置文件目录
/etc/httpd/conf.d/README
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf 主配置文件
/etc/httpd/logs 日志目录
/etc/httpd/modules 模块目录
/etc/httpd/run 运行时的进程文件路径
/usr/sbin/httpd
/usr/share/doc/httpd-2.4.6 帮助文档
/usr/share/doc/httpd-2.4.6/httpd-default.conf
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
/var/www/html 主文档目录,默认网页发布目录
/var/log/httpd 日志
192.168.1.250/a.html
url 统一资源定位符 协议://主机/路径
2.启动服务
[root@www ~]# systemctl start httpd
客户端访问
http://192.168.1.252
-----------------------------搭建基本web站点---------------
[root@www ~]# cd /var/www/html/
[root@www html]# echo "hello apache" > index.html
客户端:
[root@client ~]# firefox http://192.168.1.252 &
配置文件详解 / 日志格式
# vim /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd" #服务器的根路径,文件中所有的相对路径都是相对它而言的。
Listen 80 #监听端口
Include conf.modules.d/*.conf #包含辅助配置文件目录下的所有以.conf结尾的文件
User apache #运行web服务的用户
Group apache
ServerAdmin root@localhost #管理员邮件地址
#ServerName www.example.com:80 #服务器的名字
ServerName www.qf.com:80
<Directory /> ---容器,对整个目录中的东西进行设置,权限等等
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html" #web服务文档根路径
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks #Indexes:索引目录,(默认没有主页时),允许索引目录 FollowSymLinks:支持符号链接 软连接
AllowOverride None #和访问权限有关 可以进行认证
None --不使用认证
all--应用所有的认证指令
AuthConfig --允许使用与认证授权相关的指令
Require all granted #访问控制 所有人放行
</Directory>
<IfModule dir_module>
DirectoryIndex index.html #网站索引页的名称
</IfModule>
<Files ".ht*"> #以所有.ht开头的文件不能进行访问
Require all denied
</Files>
ErrorLog "logs/error_log" #错误日志的设定
LogLevel warn #日志级别
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined #日志格式规定
LogFormat "%h %l %u %t \"%r\" %>s %b" common #日志格式规定
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio #日志格式规定
</IfModule>
CustomLog "logs/access_log" combined #访问日志
</IfModule>
<IfModule alias_module>
# Alias /webpath /full/filesystem/path #给路径设置别名 意味着访问http://Server_ip/webpath时,其页面文件来自于/full/filesystem/path中
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" #脚本路径的别名
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types #支持哪些非二进制文件
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8 #默认字符集
#EnableMMAP off
EnableSendfile on
IncludeOptional conf.d/*.conf #包含辅助配置文件目录下的所有以.conf结尾的文件
------------------------------------------------------------------------
测试配置文件语法, 建议每次修改配置文件后都测试一下
[root@server ~]# httpd -t
Syntax OK
------------------------------------------------------------------------
客户端以服务器主机名访问
1.添加解析记录(在客户端上添加)
# vim /etc/hosts
192.168.1.252 www.qf.com
2.访问
http://www.qf.com/
日志格式
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
%h 客户端地址
%l 远程登陆的登陆名,通常-
%u 认证时的远程登陆名,通常-
%t 接收请求时的时间,为标准的英文格式+时区 [19/Jul/2017:17:22:13 +0800]
%r 请求报文的起始行
%>s 响应状态码
%b 字节数
%{Referer}i 从什么地方过来
%{User-Agent}i 客户端浏览器
访问控制
访问控制:
# vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
order allow,deny
allow from all
deny from 192.168.1.249
</Directory>
主要看order, 先看后面的,匹配到即停止
-------------------------------------------------------
用户验证:
1.创建用户
# htpasswd -c /var/www/html/.htpasswd http1
New password:
Re-type new password:
Adding password for user http1
-c 创建新文件 第一次创建使用
# htpasswd /var/www/html/htpasswd http2
2.修改配置文件
# vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
AllowOverride AuthConfig
AuthType Basic #验证类型
AuthName "name&passwd" #验证的名字
Authuserfile "/var/www/html/.htpasswd" #验证文件
Require valid-user #合法用户可以访问
</Directory>
# systemctl restart httpd
3.测试
http://192.168.1.252
需要输入正确的用户名和密码才可以登陆
虚拟主机
web服务器中虚拟主机的类型:
1)基于域名的虚拟主机
最常用的虚拟主机
通过域名来标识,不同的域名可以访问到不同的网站
2)基于ip的虚拟主机
不同的ip地址可以访问到不同的网站
监听的IP不一样,一个IP对应一个网站
3)基于端口的虚拟主机
不同的网站使用不同的监听端口
缺点:用户很难记忆多个端口
监听的端口不一样,访问时一定要带上端口号,每个端口号都要监听起来
虚拟主机用处
对于访问量不是特别大,而且主机资源充足的服务器,可以划分虚拟主机,使其资源得到充分的利用。
--------------------------------------------------
基于域名的虚拟主机:
服务器端配置: 192.168.10.11
# cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/
# vim /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/var/www/html/web1"
ServerName www.web1.com
ErrorLog "/var/log/httpd/web1-error_log"
CustomLog "/var/log/httpd/web1-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/web2"
ServerName www.web2.com
ErrorLog "/var/log/httpd/web2-error_log"
CustomLog "/var/log/httpd/web2-access_log" common
</VirtualHost>
# systemctl restart httpd
# mkdir /var/www/html/web{1,2}
# echo "web1" > /var/www/html/web1/index.html
# echo "web2" > /var/www/html/web2/index.html
客户端解析
# vim /etc/hosts
192.168.10.11 www.web1.com
192.168.10.11 www.web2.com
客户端访问测试
# curl www.web1.com
web1
# curl www.web2.com
web2
--------------------------------------------------------------
基于端口的虚拟主机:
基于端口的虚拟主机
不同的网站使用不同的端口
服务器修改虚拟主机配置文件:
# vim /etc/httpd/conf.d/httpd-vhosts.conf
Listen 81
<Directory "/webs">
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot "/webs/google"
ServerName www.google.com
ErrorLog "/var/log/httpd/google-error_log"
CustomLog "/var/log/httpd/google-access_log" common
</VirtualHost>
<VirtualHost *:81>
DocumentRoot "/webs/163"
ServerName www.163.com
ErrorLog "/var/log/httpd/163-error_log"
CustomLog "/var/log/httpd/163-access_log" common
</VirtualHost>
LAMP -- 实战
LAMP 是一个缩写,它指一组通常一起使用来运行动态网站或者服务器的自由软件:
Linux,操作系统;
Apache,网页服务器;
MySQL,数据库管理系统(或者数据库服务器);
PHP 和有時 Perl 或 Python,脚本语言。
实战: 基于LAMP部署上线qqfarm项目
1、安装apache
# yum install httpd -y
2、安装数据库以及php
# yum install mariadb-server php php-mysql -y
3、修改apache配置文件,让apache和php可以进行联动
# vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex index.html index.php //大概172行,加上index.php
</IfModule>
4、编写虚拟主机配置文件
# vim /etc/httpd/conf.d/qqfarn.conf
<Directory "/qqfarm">
AllowOverride None
Require all granted
</Directory>
<VirtualHost 10.3.148.201:80>
ServerAdmin root@localhost
DocumentRoot "/qqfarm"
ServerName qqfarm.qf.com
</VirtualHost>
5、测试
# vim /qqfarm/index.php
<?php
phpinfo();
?>
# systemctl restart httpd
【在浏览器进行访问虚拟机的IP地址,观察是否能访问php的版本信息页面】
使用浏览器访问虚拟机的IP地址,如果能看到以下页面就OK了

6、上线项目
将应用传到服务器的/root(略)
解压应用
# cd /root
# unzip farm-ucenter1.5.zip
# rm -rf /qqfarm/*
# cp -r upload/* /qqfarm
7. 导入数据库
# systemctl start mariadb
# mysql -uroot
MariaDB [(none)]> create database qqfarm;
MariaDB [(none)]> exit
# cd /qqfarm
# mysql -uroot -D qqfarm < /qqfarm/qqfarm.sql
8. 浏览器访问:
http://虚拟机ip/

9. 修改/etc/php.ini文件
# vim /etc/php.ini
# systemctl restart httpd

10. 修改目录权限
# cd /qqfarm
# chmod 777 -R bbs/ home/ ucenter/
11. 重启apache
# systemctl restart httpd
刷新网页,所有环境OK后点击下一步


安装完成后用浏览器访问:http://云服务器的ip/home