可能会遇到无法连接到root用户,解决办法如下:
进入到配置文件 vim /etc/ssh/sshd_config
修改 permitrootlogin:yes
重启ssh服务 service ssh restart
11. 手动配置DNS
进入到配置文件hosts: sudo vim /etc/hosts
在文件底部添加你需要的项,格式: <IP> <HOSTNAME>.<DOMAIN> <ALIAS>
示例: 192.168.190.130 video.imooc.com
192.168.190.130 bbs.imooc.com
192.168.190.130 oa.imooc.com
完成后保存退出,重启网络:sudo /etc/init.d/networking restart
到浏览器中输入video.imooc.com等三个域名检验,发现跟输入192.168.190.130指向同一个页面。最开始设置好以后在自己电脑上怎么也打不开“It Works”页面,后来发现在Windows客户端查看的话要设置Windows端的hosts文件:打开C:\Windows\System32\drivers\etc\hosts,加入三台虚拟主机的配置:192.168.190.130 video.imooc.com。
12. 用xshell远程连接到Ubuntu服务器创建虚拟主机文件
(1)批量创建文件夹:sudo mkdir -p /var/www/html/{video,bbs,oa}
(2)创建完文件夹后分别为这三个文件夹创建示例文件:
d /video/
sudo vim index.html
(3) 编辑文件:“Welcome to Video Site”
重复(2)(3)两步给bbs、oa创建示例文件。
(5)创建虚拟主机文件:
默认情况下,apache有一个默认的虚拟主机文件叫000-default.conf。我们将会复制000-default.conf文件内容到我们新的虚拟主机配置文件中。
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/video.local.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/bbs.local.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/oa.local.conf
(6)修改虚拟主机文件
确保虚拟主机配置文件末尾包含.conf扩展名。现在,修改video.local.conf文件以符合需求:
sudo vi /etc/apache2/sites-available/video.local.conf
修改后的文件如下:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@video.local
ServerName video.imooc.com
DocumentRoot /var/www/html/video/public_html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
重复(6)步骤修改bbs.local.conf oa.local.conf
(7)修改虚拟主机文件后,禁用默认的虚拟主机配置(000.default.conf),然后启用新的虚拟主机配置,如下所示。
sudo a2dissite 000-default.conf
sudo a2ensite video.local.conf
sudo a2ensite bbs.local.conf
sudo a2ensite oa.local.conf
(8)重启Apache服务器,测试网页
sudo service apache2 restart
打开地址video.imooc.com bbs.imooc.com oa.imooc.com,页面如下:
13. MySQL数据存储目录迁移:
(1)停止数据库服务:sudo service mysql stop
(2)创建与MySQL文件夹权限一致的文件夹(一般是挂载硬盘,但目前学习阶段没有挂载硬盘)来存放备份:sudo mkdir /mysqldata