网站代码
PHP---LNMP
Java----LNMP
在阿里云购买一台 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
先上传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]#
[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
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
[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]#
[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]# 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]#
注:tomcat默认的端口是8080,如果你的环境是云服务器,必须配置8080的安全组,浏览器才能正常显示
[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>catalina.sh
properties 属性 [ˈprɑpərtiz]
1>server.xml :主配置文件,相当于nginx.conf ※ ※ ※
2>web.xml:配置扩展功能、额外功能
3>logging.properties:日志的一些属性
4>tomcat-users.xml:tomcat管理端用户和密码的配置文件,用于测试环境;生产环境,禁止使用。
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 #访问日志
- 开头字符集
- 注释:在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]#
- 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>安装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>首先移动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自己分配的,每个每个人的不一样)
[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之后就可以正常访问网站了
[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个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台服务器 4路 志强金牌 2TB 16*600G sas 15k),在这台机器上多运行几个tomcat,并且端口不一样
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
应用场景:是用于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(外企)
专有名词 | 含义 | |
---|---|---|
可用区 zone | 同一地区的不同机房 | |
地区 地域 region | 不同的地方 上海 北京 杭州 | |
实例 | 虚拟机 | |
RDS | 云数据库 |
1>在阿里云中搜索RDS进行创建实例,以下只是我的一个简单的配置例子,每个人可以根据自己的情况进行选择
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云数据库中,查看数据是否存在
1>在阿里云中搜索NAS,如图:
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 ~]#
注意:
[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 ~]#
1>在阿里云中搜索SLB
2>创建负载均衡
4>购买好SLB负载均衡之后进行设置
[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停掉,然后浏览器页面查看是否还能正常显示