一、tomcat
1.1 tomcat LNMT ※※※
网站代码
PHP---LNMP
Java----LNMP
1.2 JVM
- Windows版本的QQ放到Linux是否可以运行?不能
- 代码的可移植性:1份代码可以运行在不同的系统中
- JAVA程序 会被放在1个叫虚拟机容器
- JVM(Java Virtual Machine):Java虚拟机,运行Java程序,1份代码处处使用
1.2.1 JVM的核心环境---->jdk+tomcat
- JDK(Java Development Kit):Java程序运行环境
- tomcat(nginx)存放Java程序代码
1.3 准备jdk和tomcat环境
1.3.1 环境准备
在阿里云购买一台 ecs云服务器,做下简单的优化,安装基础必备软件
yum install -y tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc ntpdate cowsay sl sshpass pssh bind-utils
1.3.2 准备jdk环境(ecs云服务器上)
先上传tomcat大礼包到/app/tools下,然后进行如下操作
[root@tomcat /app/tools]# unzip tomcat.zip
[root@tomcat /app/tools]# cd tomcat/
[root@tomcat /app/tools/tomcat]# tar xf jdk-8u60-linux-x64.tar.gz
[root@tomcat /app/tools/tomcat]# mkdir -p /application
[root@tomcat /app/tools/tomcat]# mv jdk1.8.0_60/ /application/
[root@tomcat /app/tools/tomcat]# ll /application/
total 4
drwxr-xr-x 8 10 143 4096 Aug 5 2015 jdk1.8.0_60
[root@tomcat /app/tools/tomcat]# ln -s /application/jdk1.8.0_60/ /application/jdk
[root@tomcat /app/tools/tomcat]# ll /application/
total 4
lrwxrwxrwx 1 root root 25 Jul 5 09:35 jdk -> /application/jdk1.8.0_60/
drwxr-xr-x 8 10 143 4096 Aug 5 2015 jdk1.8.0_60
[root@tomcat /app/tools/tomcat]#
1.3.3 配置JDK环境变量(为了方便)
[root@tomcat /app/tools/tomcat]# cat >>/etc/profile<<'EOF'
> export JAVA_HOME=/application/jdk
> export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
> export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/
> EOF
[root@tomcat /app/tools/tomcat]# source /etc/profile
[root@tomcat /app/tools/tomcat]# java -version \\验证
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
注:当前使用的JDK有两种:
Oracle JDK(目前)
OpenJDK
1.3.4 部署Tomcat
Tomcat 是Apache软件基金会中的一个开源软件(tomcat.apache.org)
Apache对应的web服务是httpd
[root@tomcat /app/tools/tomcat]# tar xf apache-tomcat-8.0.27.tar.gz
[root@tomcat /app/tools/tomcat]# mv apache-tomcat-8.0.27 /application/
[root@tomcat /app/tools/tomcat]# ln -s /application/apache-tomcat-8.0.27/ /application/tomcat
[root@tomcat /app/tools/tomcat]# ll /application/
total 8
drwxr-xr-x 9 root root 4096 Jul 5 09:42 apache-tomcat-8.0.27
lrwxrwxrwx 1 root root 25 Jul 5 09:35 jdk -> /application/jdk1.8.0_60/
drwxr-xr-x 8 10 143 4096 Aug 5 2015 jdk1.8.0_60
lrwxrwxrwx 1 root root 34 Jul 5 10:22 tomcat -> /application/apache-tomcat-8.0.27/
[root@tomcat /app/tools/tomcat]# echo "export TOMCAT_HOME=/application
[root@tomcat /app/tools/tomcat]# tail -1 /etc/profile
export TOMCAT_HOME=/application/tomcat
[root@tomcat /app/tools/tomcat]# source /etc/profile
1.3.5 检测 tomcat jdk环境变量是否ok
[root@tomcat /app/tools/tomcat]# /application/tomcat/bin/version.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.27
Server built: Sep 28 2015 08:17:25 UTC
Server number: 8.0.27.0
OS Name: Linux
OS Version: 3.10.0-957.21.3.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_60-b27
JVM Vendor: Oracle Corporation
[root@tomcat /app/tools/tomcat]#
1.3.6 启动tomcat
[root@tomcat /app/tools/tomcat]# /application/tomcat/bin/startup.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Tomcat started.
1.3.7 查看进程、检查端口
[root@tomcat /app/tools/tomcat]# ss -lntup|grep java
tcp LISTEN 0 1 127.0.0.1:8005 *:* users:(("java",pid=13622,fd=67))
tcp LISTEN 0 100 *:8009 *:* users:(("java",pid=13622,fd=51))
tcp LISTEN 0 100 *:8080 *:* users:(("java",pid=13622,fd=46))
[root@tomcat /app/tools/tomcat]# ps -ef|grep java
root 13622 1 6 10:29 pts/1 00:00:02 /application/jdk/bin/java -Djava.util.logging.config.file=/application/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/application/tomcat/endorsed -classpath /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/application/tomcat -Dcatalina.home=/application/tomcat -Djava.io.tmpdir=/application/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 13661 13307 0 10:29 pts/1 00:00:00 grep --color=auto java
[root@tomcat /app/tools/tomcat]#
1.3.8 浏览器检查
注:tomcat默认的端口是8080,如果你的环境是云服务器,必须配置8080的安全组,浏览器才能正常显示
1.4 tomcat目录结构
[root@tomcat /application/tomcat]# ll
total 112
drwxr-xr-x 2 root root 4096 Jul 5 09:42 bin ##主要存放命令,核心的命令有startup.sh(开)、shutdown.sh(关)、catalina.sh
drwxr-xr-x 3 root root 4096 Jul 5 10:29 conf ##存放配置文件,核心配置:server.xml
drwxr-xr-x 2 root root 4096 Jul 5 09:42 lib #tomcat以后安装的插件(库文件)
-rw-r--r-- 1 root root 57011 Sep 28 2015 LICENSE
drwxr-xr-x 2 root root 4096 Jul 5 10:29 logs #日志
-rw-r--r-- 1 root root 1444 Sep 28 2015 NOTICE
-rw-r--r-- 1 root root 6741 Sep 28 2015 RELEASE-NOTES
-rw-r--r-- 1 root root 16204 Sep 28 2015 RUNNING.txt
drwxr-xr-x 2 root root 4096 Jul 5 09:42 temp
drwxr-xr-x 7 root root 4096 Sep 28 2015 webapps #类似于nginx的站点目录
drwxr-xr-x 3 root root 4096 Jul 5 10:29 work
[root@tomcat /application/tomcat]#
1.4.1 bin(主要存放命令)
1>catalina.sh
- 是shutdow.sh和startup.sh调用的时候,背后都在调用catalina.sh
- 修改tomcat参数、修改,修改这个文件
2>startup.sh
3>shutdown.sh #关闭tomcat之后,一定要检查端口和进程,是否关闭
1.4.2 conf(存放配置文件)
properties 属性 [ˈprɑpərtiz]
1>server.xml :主配置文件,相当于nginx.conf ※ ※ ※
2>web.xml:配置扩展功能、额外功能
3>logging.properties:日志的一些属性
4>tomcat-users.xml:tomcat管理端用户和密码的配置文件,用于测试环境;生产环境,禁止使用。
1.4.3 logs
Destroying 毁灭
startup 启动
error 错误
1>catalina.out ※ ※ ※
tomcat最核心的日志,这个日志默认会被轮询(定时切割),切割之后catalina.out日志内容不会被切割
2>catalina.2019-7-5.log #中间日期,是catalina.out的切割日志
3>localhost_access_log.2019-07-05.txt #访问日志
1.5 配置tomcat管理端
- 开头字符集
- 注释:在xml格式中
- rolename 角色(admin-gui、manager-gui、host-gui)
1.5.1 配置tomcat-users.xml
[root@oldboy /application/tomcat]# cat conf/tomcat-users.xml
1.5.2 重启tomcat使配置生效
[root@tomcat /application/tomcat]# /application/tomcat/bin/shutdown.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
[root@tomcat ~]# ps -ef|grep java
root 6305 6261 0 10:13 pts/0 00:00:00 grep --color=auto java
[root@tomcat ~]# ss -lntup|grep java
[root@tomcat /application/tomcat]# /application/tomcat/bin/startup.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@tomcat /application/tomcat]#
1.6 tomcat的主配置文件server.xml
8080 http协议的端口
8005 shutdown端口,telnet连接上这个端口,输入SHUTDOWN暗号,关闭tomcat,比较危险,估默认只能本地连接8005端口
管理端存放用户名密码的文件及存放方式
指定http协议的端口,https用8443端口
8008 AJP与Apache进行通讯用的
- 从
结束,相当于nginx中server虚拟机主机
Tomcat Nginx Host name="localhost" server_name 域名 appBase="webapps" root 站点目录
unpackWARs="true" #自动解压 app.war
autoDeploy="true" #Deploy 部署 自动加载到tomcat
#指定日志的文件和日志内容的格式
1.7 Tomcat部署app(应用)
1.7.1 准备数据库
1>安装mariadb-server
[root@tomcat ~]# yum install -y mariadb-server
2>启动mariadb,并设置开机自启
[root@tomcat ~]# systemctl start mariadb.service
[root@tomcat ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@tomcat ~]#
3>进入数据库,创建数据库和用户
[root@tomcat ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
4>创建jpress数据库
MariaDB [(none)]> create database jpress DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
5>查看jpress数据库是否创建成功
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| jpress |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
6>创建用户,并查看
MariaDB [(none)]> grant all on jpress.* to jpress@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on jpress.* to jpress@'172.16.%.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+--------+------------+
| user | host |
+--------+------------+
| root | 127.0.0.1 |
| jpress | 172.16.%.% |
| root | ::1 |
| | localhost |
| jpress | localhost |
| root | localhost |
| | tomcat |
| root | tomcat |
+--------+------------+
8 rows in set (0.00 sec)
7>删除为空的用户
MariaDB [(none)]> drop user ''@localhost;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@tomcat;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+--------+------------+
| user | host |
+--------+------------+
| root | 127.0.0.1 |
| jpress | 172.16.%.% |
| root | ::1 |
| jpress | localhost |
| root | localhost |
| root | tomcat |
+--------+------------+
6 rows in set (0.00 sec)
MariaDB [(none)]>
MariaDB [(none)]> Bye
[root@tomcat ~]#
8>测试数据库
[root@tomcat ~]# mysql -ujpress -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> Bye
[root@tomcat ~]#
扩展 mysql -e 参数 非交互式执行SQL语句
[root@tomcat ~]# mysql -ujpress -p -e 'select user,host from mysql.user;'
Enter password:
ERROR 1142 (42000) at line 1: SELECT command denied to user 'jpress'@'localhost' for table 'user'
[root@tomcat ~]# mysql -ujpress -p -e 'select user();'
Enter password:
+------------------+
| user() |
+------------------+
| jpress@localhost |
+------------------+
[root@tomcat ~]#
1.7.2 准备app(war包)
1>首先移动war包到站点目录,并重命名
##首先移动war包到站点目录,并重命名
[root@tomcat /app/tools/tomcat]# mv jpress-web-newest.war /application/tomcat/webapps/jpress.war
[root@tomcat /app/tools/tomcat]# ll /application/tomcat/webapps/
total 20336
drwxr-xr-x 14 root root 4096 Jul 5 09:42 docs
drwxr-xr-x 6 root root 4096 Jul 5 09:42 examples
drwxr-xr-x 5 root root 4096 Jul 5 09:42 host-manager
drwxr-xr-x 7 root root 4096 Jul 5 12:43 jpress
-rw-r--r-- 1 root root 20797013 Mar 3 2017 jpress.war
drwxr-xr-x 5 root root 4096 Jul 5 09:42 manager
drwxr-xr-x 3 root root 4096 Jul 5 09:42 ROOT
[root@tomcat /app/tools/tomcat]#
2>在浏览器输入http://47.92.92.94:8080/jpress/install安装网站(注:这里的ip是我购买ecs自己分配的,每个每个人的不一样)
安装完成之后需要重启tomcat
[root@tomcat /app/tools/tomcat]# pkill java #注:pkill java会将虚拟机中的所有Java进程都杀掉,如果你的虚拟机中有多个tomcat的话,请慎用;可以用/application/tomcat/bin/shutdown.sh
#停止tomcat进程之后一定要检查进程和端口是否都已经没有了,一定要保证都没有了
[root@tomcat /app/tools/tomcat]# ps -ef|grep java
root 14452 13307 0 13:02 pts/1 00:00:00 grep --color=auto java
[root@tomcat /app/tools/tomcat]# ss -lntup|grep java
[root@tomcat /app/tools/tomcat]# /application/tomcat/bin/startup.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@tomcat /app/tools/tomcat]#
重启tomcat之后就可以正常访问网站了
网站地址:http://47.92.92.94:8080/jpress/
网站后台地址:http://47.92.92.94:8080/jpress/admin/login
注:以上的数据库在本地,要改为远程服务器的修改db.properties文件就行
[root@tomcat /application/tomcat/webapps/jpress/WEB-INF/classes]# cat db.properties
#Auto create by JPress
#Fri Jul 05 13:01:50 CST 2019
db_name=jpress
db_host_port=3306
db_tablePrefix=jpress_
db_host=localhost
db_password=*****
db_user=*****
温馨提示:
- 关闭Tomcat之后一定要检查端口和进程是否完全关闭
- 如果没有完全关闭,会导致再启动tomcat时,会有大量的日志在catalina.out中,而且增加的非常快,最终会导致磁盘满了
1.8 Tomcat与负载均衡
1个tomcat存放1个app
1个tomcat存放1个app
比如有2台负载均衡,前面就必须要有个负载均衡
upstream
proxyupstream app_pools { server 10.0.0.7:8080; server 10.0.0.7:8081; server 10.0.0.7:8082; server 10.0.0.8:8080; }
1.9 Tomcat多实例
比如:有一台机器,配置(1台服务器 4路 志强金牌 2TB 16*600G sas 15k),在这台机器上多运行几个tomcat,并且端口不一样
1.10 tomcat监控
1.10.1 命令行检查
1>查看进程信息
[root@tomcat /application/tomcat/webapps/jpress/WEB-INF/classes]# ps -ef|grep java
root 14463 1 0 13:02 pts/1 00:00:19 /application/jdk/bin/java #Java命令本身
-Djava.util.logging.config.file=/application/tomcat/conf/logging.properties #指定日志配置文件
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.endorsed.dirs=/application/tomcat/endorsed
-classpath /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
-Dcatalina.base=/application/tomcat -Dcatalina.home=/application/tomcat #tomcat软件的目录
-Djava.io.tmpdir=/application/tomcat/temp org.apache.catalina.startup.Bootstrap #临时目录
start
如果要在上面添加一些参数,修改的文件是catalina.sh
2>jps -lvm #专门检查Java进程
[root@tomcat /application/tomcat/bin]# jps -lvm
16744 org.apache.catalina.startup.Bootstrap start -
Djava.util.logging.config.file=/application/tomcat/conf/logging.properties -
Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -
Djava.endorsed.dirs=/application/tomcat/endorsed -
Dcatalina.base=/application/tomcat -Dcatalina.home=/application/tomcat -
Djava.io.tmpdir=/application/tomcat/temp
16813 sun.tools.jps.Jps -lvm -
Denv.class.path=.:/application/jdk/lib:/application/jdk/jre/lib:/application/
jdk/lib/tools.jar -Dapplication.home=/application/jdk1.8.0_60 -Xms8m
3>show-busy-java-threads.sh #显示当前系统中 java进程、负载、cpu 使用率较高
ps -ef 进程信息
进程 process pid,实际相当于房子或空间
线程 thread,实际是处理用户请求
查看进程和线程的关系,pstree -pa
1.10.2 开启tomcat监控
应用场景:是用于zabbix监控tomcat zabbix监控tomcat的方法之一
1>开启监控功能,在catalina.sh中的第二行加入以下内容
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=IP地址"
分别代表的意思:
CATALINA_OPTS="$CATALINA_OPTS .*" #表示Java程序启动的时候,增加的参数
-Dcom.sun.management.jmxremote #开启tomcat远程监控功能
-Dcom.sun.management.jmxremote.port=12345 #指定端口,什么都行,别跟现有的冲突就行
-Dcom.sun.management.jmxremote.authenticate=false #是否开启认证模式(用户名、密码)
-Dcom.sun.management.jmxremote.ssl=false #是否开启https
-Djava.rmi.server.hostname=IP地址" #监听的地址(本地)。实际工作写上服务器的内网ip地址;我们测试环境中,可以写上服务器的公网ip
将上面的内容添加到catalina.sh中,然后重启tomcat
[root@tomcat ~]# ss -lntup |grep java
[root@tomcat ~]# ss -lntup |grep java
tcp LISTEN 0 100 *:8009 : users:(("java",pid=17028,fd=54))
tcp LISTEN 0 50 *:34345 : users:(("java",pid=17028,fd=19))
tcp LISTEN 0 100 *:8080 : users:(("java",pid=17028,fd=50))
tcp LISTEN 0 50 *:33142 : users:(("java",pid=17028,fd=21))
tcp LISTEN 0 50 *:12345 : users:(("java",pid=17028,fd=20))
2>windows下面 通过java 命令 连接tomcat (模拟zabbix监控tomcat)
开发环境:jdk
命令1:jconsole
命令2:jvisualvm
二、云服务器
国内:阿里云、腾旭、华为
国外:aws(外企)
2.1 阿里云服务器的架构
2.2 专有名词
专有名词 | 含义 | |
---|---|---|
可用区 zone | 同一地区的不同机房 | |
地区 地域 region | 不同的地方 上海 北京 杭州 | |
实例 | 虚拟机 | |
RDS | 云数据库 |
NAS和OSS的相同点和不同点:
- 都是存放用户上传的附件
- NAS是文件存储,实现nfs共享存储,价格比较贵
- OSS是对象存储。大容量、访问频率高/低
- OSS的价格分为几种:1>访问频率低、性能不高的就便宜点;2>要求实时性好、速度又快的就会贵点
- OSS的使用,有两种方法:
- 1>把它真的的当对象存储用,就是硬盘里的,当网盘用
- 2>通过程序调用,就是在程序代码里写,只要用户传数据,就存到OSS
2.3 购买ECS云服务器,同1.3.1 ※※※
2.4 购买RDS云数据库 (数据库迁移)※※※
2.4.1 购买RDS云数据库的过程:
1>在阿里云中搜索RDS进行创建实例,以下只是我的一个简单的配置例子,每个人可以根据自己的情况进行选择
2>购买好RDS云数据库之后,因为暂时没有ip地址,故无法连接,可以点击图中的任意一个进入下一个页面,先设置白名单,就可以获得RDS的内网地址
3>进入白名单列表页面,添加或修改已有的都可以
注:设置的白名单可以是多个ip或多个网段,中间用英文的逗号隔开,也可以直接写0.0.0.0/0,所有的ip都可以,但这个不安全,不建议设置。
4>白名单设置成功之后,就可以看到内网地址了(每个人的都不一样)
5>上面的内网地址是域名,要想知道具体的内网ip地址,去xshell中ping下就知道了
这样RDS云数据库就买好了
2.4.2 数据库迁移:
1>从ECS云服务器里导出备份jpress数据库到/root目录下
[root@tomcat ~]# mysqldump -ujpress -p -B jpress >/root/jpress.sql
Enter password:
[root@tomcat ~]# ll
total 20
-rw-r--r-- 1 root root 17409 Jul 5 17:18 jpress.sql
[root@tomcat ~]#
2>远程进入购买的RDS云数据库中创建空的jpress数据库
[root@tomcat ~]# mysql -uwwj_mysql -p -h rm-8vbzbcm62xy92g82q.mysql.zhangbei.rds.aliyuncs.com
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1997
Server version: 5.7.25-log Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> create database jpress DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| jpress |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
MySQL [(none)]> show tables from jpress;
Empty set (0.00 sec)
MySQL [(none)]>
3>把备份的jpress数据库还原到RDS云数据库上,并查看
[root@tomcat ~]# mysql -uwwj_mysql -p -h rm-8vbzbcm62xy92g82q.mysql.zhangbei.rds.aliyuncs.com show tables from jpress;
+-------------------+
| Tables_in_jpress |
+-------------------+
| jpress_attachment |
| jpress_comment |
| jpress_content |
| jpress_mapping |
| jpress_metadata |
| jpress_option |
| jpress_taxonomy |
| jpress_user |
+-------------------+
8 rows in set (0.00 sec)
MySQL [(none)]>
4>停止ECS云服务器上的mysql服务
[root@tomcat ~]# systemctl stop mariadb.service
[root@tomcat ~]# systemctl disable mariadb.service
Removed symlink /etc/systemd/system/multi-user.target.wants/mariadb.service.
[root@tomcat ~]#
5>修改数据库配置
vim /application/tomcat/webapps/jpress/WEB-INF/classes/db.properties
6>重启tomcat服务
[root@tomcat ~]# pkill java #或/application/tomcat/bin/shutdown.sh
[root@tomcat ~]# ss -lntup|grep java
[root@tomcat ~]# ps -ef|grep java
root 15205 14908 0 17:32 pts/0 00:00:00 grep --color=auto java
[root@tomcat ~]# /application/tomcat/bin/startup.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@tomcat ~]#
7>测试数据库是否迁移成功
打开部署好的jpress网站,刷新查看网站是否正常,再在网站随便写个文章,远程进入RDS云数据库中,查看数据是否存在
2.5 购买文件存储NAS (部署nfs存储)※※※
2.5.1 购买文件存储NAS的过程
1>在阿里云中搜索NAS,如图:
2>创建文件系统
3>文件系统创建好之后,添加挂载点
4>点击文件系统列表中管理进入详细页面,可以看到挂载地址或挂载命令
到这里NAS文件存储系统就购买好了,下面就到ECS云服务器中进行挂载
2.5.1 ECS云服务器中安装nfs-utils准备进行挂载
1>安装nfs-utils,启动nfs-utils服务,并设置开机自启
[root@tomcat ~]# yum install -y nfs-utils
[root@tomcat ~]# systemctl start nfs-utils
[root@tomcat ~]# systemctl enable nfs-utils
[root@tomcat ~]#
2>进行挂载测试
[root@tomcat ~]# mount -t nfs 9db184ad00-hrk84.cn-zhangjiakou.nas.aliyuncs.com:/ /mnt
[root@tomcat ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 3.1G 35G 9% /
devtmpfs 909M 0 909M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 456K 919M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
tmpfs 184M 0 184M 0% /run/user/0
9db184ad00-hrk84.cn-zhangjiakou.nas.aliyuncs.com:/ 1.0P 0 1.0P 0% /mnt
[root@tomcat ~]#
3>挂载点迁移
[root@tomcat ~]# mv /application/tomcat/webapps/jpress/attachment/* /mnt
[root@tomcat ~]# ll /application/tomcat/webapps/jpress/attachment/
total 0
[root@tomcat ~]# umount /mnt
[root@tomcat ~]# mount -t nfs 9db184ad00-hrk84.cn-zhangjiakou.nas.aliyuncs.com:/ /application/tomcat/webapps/jpress/attachment/
[root@tomcat ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 3.1G 35G 9% /
devtmpfs 909M 0 909M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 456K 919M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
tmpfs 184M 0 184M 0% /run/user/0
9db184ad00-hrk84.cn-zhangjiakou.nas.aliyuncs.com:/ 1.0P 0 1.0P 0% /application/apache-tomcat-8.0.27/webapps/jpress/attachment
[root@tomcat ~]#
2.6 目前只部署了一台web服务器(ECS云服务器),如果要多台,将上面部署好网站的web服务器先做快照和镜像,再根据镜像创建多台web服务器就可以
注意:
- 创建快照之前一定要检查好这台ECS云服务器里面的服务是否都设置开机自启动,挂载是否永久挂载,否则后面根据镜像创建的云服务器里面的服务都要单独启动,很麻烦
- 永久挂载可以写入到/etc/fstab中,也可以写入/etc/rc.d/rc.local中
- 对一些无法通过systemctl设置开机自启动的服务,将他们的启动方式写入到/etc/rc.d/rc.local中
- 如果写入到/etc/rc.d/rc.local中,就必须给/etc/rc.d/rc.local这个文件添加可执行权限
[root@tomcat ~]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
source /etc/profile #注意:在启动tomcat时,需要配置在/etc/profile中配置好环境变量,估这里需要source /etc/profile生效环境变量,否则无法启动,也可以写为: . /etc/profile
mount -t nfs 9db184ad00-hrk84.cn-zhangjiakou.nas.aliyuncs.com:/ /application/tomcat/webapps/jpress/attachment/
/application/tomcat/bin/startup.sh
[root@tomcat ~]# chmod +x /etc/rc.d/rc.local
[root@tomcat ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 619 Jul 5 18:21 /etc/rc.d/rc.local
[root@tomcat ~]#
2.7 购买SLB负载均衡
2.7.1 购买SLB的过程
1>在阿里云中搜索SLB
2>创建负载均衡
3>选择负载均衡的简单配置(根据自己的情况来定)
4>购买好SLB负载均衡之后进行设置
到这里简单的SLB云负载均衡就购买配置完成了
2.7.2 在两台web云服务器上简单配置个页面,然后在浏览器测试负载均衡
[root@tomcat ~]# echo web01 >/application/tomcat/webapps/ROOT/oldboy.jsp
[root@tomcat ~]#
[root@tomcat02 ~]# echo web02 >/application/tomcat/webapps/ROOT/oldboy.jsp
[root@tomcat02 ~]#
测试方法:可以试着将其中一台web服务器上的tomcat停掉,然后浏览器页面查看是否还能正常显示