企业级四七层负载实战项目
2023-12-13 03:48:50
在实验之前关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
配置环境
192.168.91.5 #配置php
192.168.91.6 #配置tomcat
192.168.91.7 #配置nginx代理
192.168.91.8 #配置nginx代理
192.168.91.9 #配置lvm代理
192.168.91.10 #配置lvm代理
并为两台lvm代理服务器做keepalived高可用
配置php
#下载php
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php71w-xsl php71w php71w-ldap php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath php71w-mcrypt -y
yum install -y php71w-fpm
systemctl start php-fpm
#下载nginx并对php进行代理
server {
listen 80;
server_name localhost;
location ~ \.php$ {
root /www/html; #指定网站目录
fastcgi_pass 127.0.0.1:9000; #开启fastcgi连接php地址
fastcgi_index index.php; #指定默认文件
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #站点根目录,取决于root配置项
include fastcgi_params; #包含fastcgi使用的常量
}
}
#vim index.php
<?php
phpinfo();
?>
启动nginx
我们可用通过192.168.91.5/index.php在浏览器上访问测试?
配置tomcat
#安装jdk
tar zxvf jdk-8u191-linux-x64.tar.gz -C /usr/local/
mv /usr/local/jdk1.8.0_191/ java /usr/local/java
vim /etc/profile
添加下面的命令
JAVA_HOME=/usr/local/java #指定java安装目录
PATH=$JAVA_HOME/bin:$PATH #用于指定java系统查找命令的路径
export JAVA_HOME PATH #类的路径,在编译运行java程序时,如果有调用到其他类的时候,在classpath中寻找需要的类。
source /etc/profile
#下载tomcat
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz
tar zvxf apache-tomcat-8.5.42.tar.gz -C /usr/local
mv /usr/local/appche-tomcat-8.5.42 /usr/local/tomcat
/usr/local/tomcat/bin/startup.sh #启动
我们可用通过192.168.91.6/index.php在浏览器上访问测试?
配置nginx代理(两台服务器配置相同)
cd /etc/nginx/conf.d
cp default.conf default.conf.bak
mv default.conf proxy.conf
# vim proxy.conf
server {
listen 80;
server_name localhost;
charset koi8-r;
access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://192.168.91.5:8080;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /index.php {
proxy_pass http://192.168.91.6:80;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
配置lvs+keepalived高可用(master)
yum -y install ipvsadm keepalived
# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id master
}
vrrp_instance master {
state MASTER
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.246.16/32
}
}
virtual_server 192.168.246.16 80 {
delay_loop 6
lb_algo rr
lb_kind DR
net_mask 255.255.255.0
protocol TCP
real_server 192.168.91.7 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_port 80
connect_timeout 3
}
}
real_server 192.168.91.8 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_port 80
connect_timeout 3
}
}
}
#systemctl start keepalived
配置lvs+keepalived高可用(backup)
yum -y install ipvsadm keepalived
# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id master
}
vrrp_instance backup {
state BACKUP
interface ens33
virtual_router_id 80
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.246.16/32
}
}
virtual_server 192.168.246.16 80 {
delay_loop 6
lb_algo rr
lb_kind DR
net_mask 255.255.255.0
protocol TCP
real_server 192.168.246.144 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_port 80
connect_timeout 3
}
}
real_server 192.168.246.145 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_port 80
connect_timeout 3
}
}
}
#systemctl start keepalived
给两台nginx代理服务器lo配置vip
ip addr add dev lo 192.168.91.16/32
echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf
sysctl -p
配置完成后,我们可用在浏览器上通过vip来访问了
文章来源:https://blog.csdn.net/XX_HK/article/details/134895532
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!