haproxy
# 安装所需依赖
yum -y install gcc openssl-devel pcre-devel systemd-devel
# 下载安装包
wget -c https://www.haproxy.org/download/2.1/src/haproxy-2.1.10.tar.gz
tar zxf haproxy-2.1.10.tar.gz -C /usr/local/
cd /usr/local/haproxy-2.1.10/
make TARGET=linux-glibc
sudo make install
sudo mkdir -p /etc/haproxy
sudo mkdir -p /var/lib/haproxy
sudo touch /var/lib/haproxy/stats
sudo ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
sudo cp /usr/local/haproxy-2.1.10/examples/haproxy.init /etc/init.d/haproxy
sudo chmod 755 /etc/init.d/haproxy
sudo systemctl daemon-reload
sudo chkconfig haproxy on
sudo useradd -r haproxy
haproxy -v
systemctl start haproxy
systemctl status haproxy
# 配置haproxy配置项
/etc/haproxy/haproxy.cfg
global
log /dev/log local0
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 30000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 30000
listen stats # 定义监控页面
mode http
bind *:7804
stats refresh 30s
stats uri /stats # 访问监控页面的uri
stats realm HAProxy Stats # 监控页面的认证提示
stats auth city:City
frontend main
bind *:7805
# ez-admin-api
acl admin_acl path_beg -i /admin/
use_backend admin if admin_acl
# survey-api
acl survey_acl path_beg -i /survey/
use_backend survey if survey_acl
default_backend admin
backend admin
http-request replace-path /admin/(.*) /\1
server admin 127.0.0.1:7868 check
backend survey
http-request replace-path /survey/(.*) /\1
server survey 127.0.0.1:7869 check
- haproxy开启日志
mkdir /var/log/haproxy
chmod a+w /var/log/haproxy
编辑“/etc/rsyslog.conf”打开如下配置项:
#Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
添加如下内容
#Save haproxy log
local0.* /var/log/haproxy/haproxy.log
3. 修改“/etc/sysconfig/rsyslog”文件,内容如下
#Options for rsyslogd
#Syslogd options are deprecated since rsyslog v3.
#If you want to use them, switch to compatibility mode 2 by "-c 2"
#See rsyslogd(8) for more details
SYSLOGD_OPTIONS="-r -m 0 -c 2"
4. 配置haproxy
编辑haproxy配置文件,进行如下内容修改
log 127.0.0.1 local0 info
5. 验证是否生效
复制代码
###重启服务
systemctl restart haproxy
service rsyslog restart
###查看日志记录
tailf /var/log/haproxy/haproxy.log
nginx
rpm -ivh nginx-1.20.2-1.el7.ngx.x86_64.rpm
vim /etc/nginx/nginx.conf
/usr/sbin/nginx -t
nohup /usr/sbin/nginx -c /etc/nginx/nginx.conf &
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
tar zxf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx
# --prefix 指安装的位置
make
make install
cd /usr/local/nginx/sbin
nohup ./nginx &
./nginx -s stop
//退出命令:
./nginx -s quit
//重启
./nginx -s reload
/usr/local/nginx
[root@front-master nginx]# ls -l
total 36
drwx------ 2 nobody root 4096 Nov 15 12:27 client_body_temp
drwxr-xr-x 2 root root 4096 Nov 15 12:27 conf
drwx------ 2 nobody root 4096 Nov 15 12:27 fastcgi_temp
drwxr-xr-x 2 root root 4096 Nov 15 12:27 html
drwxr-xr-x 2 root root 4096 Nov 15 12:27 logs
drwx------ 2 nobody root 4096 Nov 15 12:27 proxy_temp
drwxr-xr-x 2 root root 4096 Nov 15 12:27 sbin
drwx------ 2 nobody root 4096 Nov 15 12:27 scgi_temp
drwx------ 2 nobody root 4096 Nov 15 12:27 uwsgi_temp
# nginx.conf
user root;
worker_processes auto;
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8001 default_server;
listen [::]:8001 default_server;
server_name nginx_vue_front;
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css application/font-sfnt;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
root /root/cloud/scene/examples/replace-component/;
location / {
try_files $uri $uri/ /index.html;
}
location ~* ^.+\.(eot|ttf|otf|woff|svg)$ {
access_log off;
add_header Cache-Control max-age=360000;
}
}
server {
listen 8004 default_server;
listen [::]:8004 default_server;
server_name nginx_vue_front;
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css application/font-sfnt;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
root /root/cloud/scene-dev/examples/replace-component/;
location / {
try_files $uri $uri/ /index.html;
}
location ~* ^.+\.(eot|ttf|otf|woff|svg)$ {
access_log off;
add_header Cache-Control max-age=360000;
}
}
}