一键部署web网页:
注意:
本次实验由阿里云官方提供资源
由于实验所需centos版本比较低为centos6.8
所以7以上版本可能会出现报错情况自行选择即可
实验所需压缩包可以根据官网进行自取:
链接地址:http://opensource.chinamoocs.com/
实验资源:
使用ssh远程工具连接公网:
解压一键部署安装包:
[root@LYX ~]# tar -zxvf cnmcs-web-env-installer.tar.gz
进入此目录:
[root@LYX ~]# cd cnmcs-web-env-installer
# 进行启动
[root@LYX cnmcs-web-env-installer]# ./install.sh
Installing mysql...
Installing java...
Installing tomcat...
Installing nginx...
http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
To address this issue please refer to the below knowledge base article
https://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
make: *** No rule to make target `build', needed by `default'. Stop.
make: *** No rule to make target `install'. Stop.
chmod: cannot access `/usr/local/chinamoocs/nginx/sbin/nginx': No such file or directory
cp: cannot create regular file `/usr/local/chinamoocs/nginx/conf/': Is a directory
sed: can't read /usr/local/chinamoocs/nginx/conf/nginx.conf: No such file or directory
sed: can't read /usr/local/chinamoocs/nginx/conf/nginx.conf: No such file or directory
[root@LYX cnmcs-web-env-installer]#
上述启动出现报错,可以进行换源来处理:
# 修改CentOS-Base.repo文件为以下内容:
[root@LYX ~]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-6.10
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6
[updates]
name=CentOS-6.10
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6
[extras]
name=CentOS-6.10
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6
[root@LYX ~]#
# 修改epel.repo文件为以下内容:
[root@LYX ~]# cat /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/epel-archive/6/$basearch
gpgcheck=0
gpgkey=http://mirrors.cloud.aliyuncs.com/epel-archive/RPM-GPG-KEY-EPEL-6
[root@LYX ~]#
加载环境变量使其生效:
[root@LYX ~]# source /etc/profile
再次进入一键部署web目录下:
[root@LYX ~]# cd cnmcs-web-env-installer
先进行停止避免出现缓存启动失败:
# 停止
[root@LYX cnmcs-web-env-installer]# ./uninstall.sh
Using CATALINA_BASE: /usr/local/chinamoocs/tomcat
Using CATALINA_HOME: /usr/local/chinamoocs/tomcat
Using CATALINA_TMPDIR: /usr/local/chinamoocs/tomcat/temp
Using JRE_HOME: /usr/local/chinamoocs/java
Using CLASSPATH: /usr/local/chinamoocs/tomcat/bin/bootstrap.jar:/usr/local/chinamoocs/tomcat/bin/tomcat-juli.jar
Shutting down MySQL.. [ OK ]
[root@LYX cnmcs-web-env-installer]#
进行启动测试:
[root@LYX cnmcs-web-env-installer]# ./install.sh
Installing mysql...
Installing java...
Installing tomcat...
Installing nginx...
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.6.6-6.el6_7.1.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-6.el6_7.1.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-6.el6_7.1.x86_64 has missing requires of mysql-libs
[root@LYX cnmcs-web-env-installer]#
[root@LYX cnmcs-web-env-installer]#启动成功查看进程————————————
[root@LYX cnmcs-web-env-installer]# ps -ef | grep tomcat
root 8373 1 33 15:21 pts/0 00:00:04 /usr/local/chinamoocs/java/bin/java -Djava.util.logging.config.file=/usr/local/chinamoocs/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/chinamoocs/tomcat/endorsed -classpath /usr/local/chinamoocs/tomcat/bin/bootstrap.jar:/usr/local/chinamoocs/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/chinamoocs/tomcat -Dcatalina.home=/usr/local/chinamoocs/tomcat -Djava.io.tmpdir=/usr/local/chinamoocs/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 8417 2412 0 15:21 pts/0 00:00:00 grep tomcat
[root@LYX cnmcs-web-env-installer]#
浏览器访问IP测试tomcat网页:
导入项目数据
注意:因为实验环境已经安装好Mysql所以不需要手动编译或下载
由于默认安装的mysql数据库root没有密码,用mysqladmin命令设置数据库root用户名密码为123456,如下所示:
mysqladmin -u root password "123456"
[root@LYX ~]# mysqladmin -u root password "123456"
Warning: Using a password on the command line interface can be insecure.
[root@LYX ~]#
使用mysql命令连接数据库,如下所示:
mysql --host=127.0.0.1 --port=3306 --user=root --password=123456
[root@LYX ~]# mysql --host=127.0.0.1 --port=3306 --user=root --password=123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.21-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
执行/root目录下数据脚本zhituyunke-db.sql,如下所示:
\. /root/zhituyunke-db.sql
mysql> \. /root/zhituyunke-db.sql
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
该脚本执行完成后,将创建名称为“zhituyunke”数据库和项目所需的表,如下所示:
show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zhituyunke |
+--------------------+
5 rows in set (0.00 sec)
进入“zhituyunke”数据库,使用show tables查看数据库表,如下所示:
use zhituyunke;
show tables ;
mysql> use zhituyunke;
Database changed
mysql> show tables ;
+----------------------+
| Tables_in_zhituyunke |
+----------------------+
| log_study |
| log_study_pos |
| log_user_visit |
| log_user_visit_pos |
| mooc_live |
| mooc_unit |
| mooc_unit_item |
| mooc_user_info |
| mooc_user_study |
+----------------------+
9 rows in set (0.00 sec)
mysql> exit
使用nginx+tomcat发布WEB程序
1,创建/usr/local/chinamoocs/mooc/webapp目录,将zhituyunke-web.zip解压到该目录下,如下所示:
[root@LYX ~]# mkdir -p /usr/local/chinamoocs/mooc/webapp
[root@LYX ~]# unzip -d /usr/local/chinamoocs/mooc/webapp -o /root/zhituyunke-web.zip
2,更改nginx配置:
进入/usr/local/chinamoocs/nginx/conf,修改nginx.conf文件
将/usr/local/chinamoocs/tomcat/webapps/ROOT修改成/usr/local/chinamoocs/mooc/webapp
如下图所示:
# 进入修改第64行
[root@LYX ~]# vim /usr/local/chinamoocs/nginx/conf/nginx.conf
3,重启nginx,如下所示:
[root@LYX ~]# /usr/local/chinamoocs/nginx/sbin/nginx -s reload
4,设置tomcat,将mysql的 jdbc 驱动jar (mysql-connector-java-5.1.30-bin.jar)复制到/usr/local/chinamoocs/tomcat/lib目录下,如下所示:
[root@LYX ~]# cp /root/mysql-connector-java-5.1.30-bin.jar /usr/local/chinamoocs/tomcat/lib
[root@LYX ~]#
5,将ROOT.xml文件复制到/usr/local/chinamoocs/tomcat/conf/Catalina/localhost目录下,如下所示:
[root@LYX ~]# mkdir -p /usr/local/chinamoocs/tomcat/conf/Catalina/localhost
[root@LYX ~]#
[root@LYX ~]# cp /root/ROOT.xml /usr/local/chinamoocs/tomcat/conf/Catalina/localhost
[root@LYX ~]#
6,修改ROOT.xml中数据库连接相关信息:
[root@LYX ~]# vim /usr/local/chinamoocs/tomcat/conf/Catalina/localhost/ROOT.xml
[root@LYX ~]#
[root@LYX ~]# 修改第29行输入刚才设置的数据库密码
7,重启tomcat,如下所示:先停止再启动
[root@LYX ~]# cd /usr/local/chinamoocs/tomcat/bin
[root@LYX bin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/chinamoocs/tomcat
Using CATALINA_HOME: /usr/local/chinamoocs/tomcat
Using CATALINA_TMPDIR: /usr/local/chinamoocs/tomcat/temp
Using JRE_HOME: /usr/local/chinamoocs/java
Using CLASSPATH: /usr/local/chinamoocs/tomcat/bin/bootstrap.jar:/usr/local/chinamoocs/tomcat/bin/tomcat-juli.jar
[root@LYX bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/chinamoocs/tomcat
Using CATALINA_HOME: /usr/local/chinamoocs/tomcat
Using CATALINA_TMPDIR: /usr/local/chinamoocs/tomcat/temp
Using JRE_HOME: /usr/local/chinamoocs/java
Using CLASSPATH: /usr/local/chinamoocs/tomcat/bin/bootstrap.jar:/usr/local/chinamoocs/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@LYX bin]#
重启成功后再次访问公网IP进行验证:
账号:admin 密码:123456 数据库密码
挂载云磁盘
步骤1:文件备份
当前系统上传的文件均保存在/usr/local/chinamoocs/mooc/webapp/repositry目录下(可以在系统后台上传视频文件查看该目录),也就是和web程序一样存放在系统盘,对于扩容来说会比较麻烦,现将上传文件存储到可扩容的数据盘上,下面开始挂载云磁盘的操作。
上传测试图片:进行提交
将原/usr/local/chinamoocs/mooc/webapp/repositry目录重命名为repositrybak,如下所示:
[root@LYX ~]# mv /usr/local/chinamoocs/mooc/webapp/repositry /usr/local/chinamoocs/mooc/webapp/repositrybak
步骤2:查看当前磁盘挂载情况
输入命令fdisk -l,查询当前系统中的数据盘,可以看到当前有未挂载的数据盘信息
[root@LYX ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00053156
Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41942016 83 Linux
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@LYX ~]#
步骤3:对数据盘进行分区
执行fdisk /dev/vdb对数据盘进行分区,在弹出的命令行中依次输入的参数是:
[root@LYX ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7b5fa38a.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-41610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-41610, default 41610):
Using default value 41610
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@LYX ~]#
再次执行命令fdisk -l,如果看到显示分区/dev/vdb1的信息,则说明数据盘分区成功
[root@LYX ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00053156
Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41942016 83 Linux
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7b5fa38a
Device Boot Start End Blocks Id System
/dev/vdb1 1 41610 20971408+ 83 Linux
[root@LYX ~]#
步骤4:对数据盘进行格式化
使用命令mkfs.ext3 /dev/vdb1对数据盘进行格式化,如下所示:
[root@LYX ~]# mkfs.ext3 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242852 blocks
262142 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@LYX ~]#
步骤5:创建挂载点
使用mkdir创建一个挂载点,然后使用命令mount将磁盘挂载上去,最后使用命令In映射目录,如下所示:
[root@LYX ~]# mkdir /home/work
[root@LYX ~]# mount /dev/vdb1 /home/work
[root@LYX ~]# mkdir /home/work/repositry
[root@LYX ~]# ln -s /home/work/repositry /usr/local/chinamoocs/mooc/webapp/repositry
# 进行查看发现/dev/vdb1已经挂载成功
[root@LYX ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 43G 4.0G 36G 10% /
tmpfs tmpfs 985M 0 985M 0% /dev/shm
/dev/vdb1 ext3 22G 181M 20G 1% /home/work
[root@LYX ~]#
将/usr/local/chinamoocs/mooc/webapp/repositrybak目录下文件迁移到/usr/local/chinamoocs/mooc/webapp/repositry下,如下所示:
[root@LYX ~]# mv /usr/local/chinamoocs/mooc/webapp/repositrybak/* /usr/local/chinamoocs/mooc/webapp/repositry
[root@LYX ~]#
步骤5:验证磁盘挂载效果
在/usr/local/chinamoocs/mooc/webapp/repositry目录下可以查看到新上传的视频文件。
[root@LYX ~]# cd /usr/local/chinamoocs/mooc/webapp/repositry
[root@LYX repositry]# ll
total 8
drwxr-xr-x 4 root root 4096 Apr 21 15:54 resource
drwxr-xr-x 2 root root 4096 Apr 21 15:54 temp
[root@LYX repositry]#
[root@LYX ~]# cd /usr/local/chinamoocs/mooc/webapp/repositry/
resource/ temp/
[root@LYX ~]# cd /usr/local/chinamoocs/mooc/webapp/repositry/resource/
i/ v/
[root@LYX ~]# cd /usr/local/chinamoocs/mooc/webapp/repositry/resource/v/2304/21/
[root@LYX 21]# ll
total 197168
-rw-r--r-- 1 root root 100839553 Apr 21 15:54 0c495302bd344ef08cc0577731feef77.mp4
-rw-r--r-- 1 root root 100839553 Apr 21 16:05 b0cac5b295474835aef631e3960f2d5b.mp4
[root@LYX 21]#
可以看到新上传的mp4视频文件。
标签:chinamoocs,tomcat,local,LYX,云课,usr,Linux,知途,root From: https://blog.51cto.com/lyx888/6213463