1)部署1台Nginx WEB前端服务器(不能跟Tomcat公用);
2)部署2台Tomcat独立服务器;
3)部署2台MYSQL主主同步架构;
4)每台服务器部署4个Tomcat实例(每两个为一个网站),通过两个域名v1.com|v2.com访问;
5)部署1台NFS文件共享服务器,网站代码统一存放在NFS服务器;
6)通过亿图或者visor将架构图画出来。
7)以上服务器再不影响使用的情况下,可以共用。
yum install -y pcre-devel zlib-devel gcc-c++
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xzf nginx-1.12.2.tar.gz
cd nginx-1.12.2.tar.gz
./configure && make && make install
/usr/local/nginx/sbin/nginx
systemctl stop firewalld
192.168.9.110
192.168.9.120
上传安装包并解压
apache-tomcat-8.0.50.tar.gz
jdk1.8.0_131.tar.gz
tar xzf apache-tomcat-8.0.50.tar.gz
tar xzf jdk1.8.0_131.tar.gz
mkdir /usr/local/tomcat
mkdir /usr/local/tomcat-1
mkdir /usr/local/tomcat-2
mkdir /usr/local/tomcat-3
mv apache-tomcat-8.0.50/* /usr/local/tomcat/
mv apache-tomcat-8.0.50/* /usr/local/tomcat-1/
mv apache-tomcat-8.0.50/* /usr/local/tomcat-2/
mv apache-tomcat-8.0.50/* /usr/local/tomcat-3/
mkdir /usr/local/jdk
mv jdk1.8.0_131/* /usr/local/jdk/
vim /etc/profile
#最后一行添加
export JAVA_HOME=/usr/local/jdk/
vim /usr/local/tomcat/conf/server.xml
/usr/local/tomcat/bin/startup.sh
/usr/local/tomcat-1/bin/startup.sh
/usr/local/tomcat-2/bin/startup.sh
/usr/local/tomcat-3/bin/startup.sh
cd /usr/local/tomcat/webapps/ROOT
rm -rf *
wget https://jaist.dl.sourceforge.net/project/jforum2/jforum-2.5.0.war
/usr/local/jdk/bin/jar -xf jforum-2.5.0.war
新建4个安装目录
更改端口号即可
两台mysql服务器,首先关闭防火墙及selinux
systemctl stop firewalld
setenforce 0
192.168.9.130
192.168.9.140
yum -y install mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
192.168.9.130
vim /etc/my.cnf
systemctl restart mariadb
mysql_secure_installation
首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
初始化MariaDB完成,接下来测试登录
mysql -uroot -p密码
192.168.9.130
grant replication slave on *.* to'tongbu'@'192.168.9.140'identified by'1';
show master status;
change master to master_host='192.168.9.130',master_user='tongbu',master_password='1',master_log_file='mysql-bin.000001',master_log_pos=393;
start slave;
show slave status\G
create database user;
show databases;
192.168.9.130
192.168.9.140
192.168.9.140
192.168.9.130
修改nginx配置文件
upstream tomcat_v1.com {
server 192.168.9.110:8080 weight=100 max_fails=2 fail_timeout=15;
server 192.168.9.110:8081 weight=100 max_fails=2 fail_timeout=15;
server 192.168.9.120:8080 weight=100 max_fails=2 fail_timeout=15;
server 192.168.9.120:8081 weight=100 max_fails=2 fail_timeout=15;
}
upstream tomcat_v2.com {
server 192.168.9.110:8082 weight=100 max_fails=2 fail_timeout=15;
server 192.168.9.110:8083 weight=100 max_fails=2 fail_timeout=15;
server 192.168.9.120:8082 weight=100 max_fails=2 fail_timeout=15;
server 192.168.9.120:8083 weight=100 max_fails=2 fail_timeout=15;
}
server {
listen 80;
server_name v1.com;
location / {
proxy_pass http://tomcat_v1.com;
proxy_set_header host $host;
root /data/v1/;
index index.jsp index.html index.htm;
}
location ~ .*\.(htm|html|txt|js|css|png|jpg|gif|jpeg|doc|xml)$
{
root /data/v1/;
expires 30d;
}
}
server {
listen 80;
server_name v2.com;
location / {
proxy_pass http://tomcat_v2.com;
proxy_set_header host $host;
root /data/v2/;
index index.jsp index.html index.htm;
}
location ~ .*\.(htm|html|txt|js|css|png|jpg|gif|jpeg|doc|xml)$
{
root /data/v2/;
expires 30d;
}
}
mkdir -p /data/v{1,2}
/usr/local/nginx/sbin/nginx -s reload
192.168.9.150
yum install nfs-utils rpcbind net-tools lsof
systemctl restart rpcbind.service
systemctl start nfs.service
systemctl enable rpcbind
systemctl enable nfs
vim /etc/exports
/data 172.168.0.0/24(rw,sync,fsid=0) 192.168.9.0/24(rw,sync,fsid=0)
mkdir -p /data
chown nfsnobody.nfsnobody /data
exportfs -rv
######查看nfs挂载情况
showmount -e localhost
yum install nfs-utils rpcbind
systemctl start rpcbind.service
systemctl start nfs.service
systemctl enable rpcbind.service
systemctl enable nfs.service
mount -t nfs 192.168.9.150:/data /data
vi /etc/fstab
192.168.9.100:/data /data nfs nolock 0 0
192.168.9.100
mount -t nfs 192.168.9.150:/data /v1
mount -t nfs 192.168.9.150:/data /v2
192.168.9.110
mount -t nfs 192.168.9.150:/data /usr/local/tomcat/webapps/ROOT/
mount -t nfs 192.168.9.150:/data /usr/local/tomcat-1/webapps/ROOT/
mount -t nfs 192.168.9.150:/data /usr/local/tomcat-2/webapps/ROOT/
mount -t nfs 192.168.9.150:/data /usr/local/tomcat-3/webapps/ROOT/
192.168.9.120(与110操作相同挂载)
/usr/local/nginx/sbin/nginx -s reload
windows访问需要修改C:\Windows\System32\drivers\etc下的hosts文件
create database jforum charset=utf8;
grant all privileges on jforum.* to 'root'@'192.168.9.100' identified by '1' with grant option;