标签:lamp 二进制文件 mysql pvs 打开 解压 The def protoc
101、102机器tar xvf haproxy-1.9.8.tar.gz
cd haproxy-1.9.8
make ARCH=x86_64 TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
cp haproxy /usr/sbin/
vim /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Banlancer
After=syslog.target network.target
[Service]
ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
mkdir /etc/haproxy
useradd -r -s /sbin/nologin haproxy
mkdir /var/lib/haproxy
chown haproxy.haproxy /var/lib/haproxy -R
vim /etc/haproxy/haproxy.cfg
global
maxconn 65536
chroot /usr/local/haproxy
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin (打开socket文件,也可以不打开注释掉)
uid 1000
gid 1000
daemon
nbproc 1
cpu-map 1 0
#cpu-map 2 1
#cpu-map 3 2
#cpu-map 4 3
spread-checks 5
pidfile /run/haproxy.pid
#log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 65536
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
#HTTP访问入口===============================================================
listen web_http
bind 192.168.66.101:80
mode tcp
#log global
balance roundrobin
server web1 192.168.66.103:80 check inter 3000 fall 2 rise 5
server web2 192.168.66.104:80 check inter 3000 fall 2 rise 5
yum install keepalived
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@magedu.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id s2.pengbo.com (防止名字冲突,建议两台机器改为不同名的机器)
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_iptables
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VIP1 {
state MASTER (102机器改为BACKUP)
interface eth0
virtual_router_id 66 (在同一网段内,要保证该值不冲突)
priority 100 (102机器应改为低于100的值)
advert_int 2
unicast_src_ip 192.168.66.102 (这个地方填写本机地址)
unicast_peer {
192.168.66.101 (填写一起监听的keepalive机器)
}
authentication {
auth_type PASS
auth_pass linux36
}
virtual_ipaddress {
192.168.66.200 dev eth0 label eth0:0 (设置一个虚拟vip地址)
}
}
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1 (打开转发功能)
net.ipv4.ip_nonlocal_bind = 1 (使其能够监听自身没有的IP地址)
sysctl -p
systemctl start haproxy keepalived
tar xf nginx-1.16.0.tar.gz
./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
make
make install
useradd -r -s /usr/sbin/nologin nginx
vim nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
mv nginx.service /usr/lib/systemd/system/
ln -sv /apps/nginx/sbin/nginx /usr/sbin/
vim /apps/nginx/conf/nginx.conf
user nginx;
worker_processes auto;
pid logs/nginx.pid;
给wordpress单独建一个访问路径
location /wordpress {
root html;
index index.php index.htm;
}
打开PHP功能
location ~ \.php$ {
root /apps/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
nginx
mkdir /apps/nginx/html/wordpress
yum install libxml2-devel bzip2-devel libmcrypt-devel bzip2
tar xvf php-7.3.5
./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo
make && make install
cp php.ini-production /etc/php.ini
vim /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Shanghai"
cp php-7.3.5/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
或者 cp php-7.3.5/sapi/fpm/php-fpm.service /usr/lib/systemd/system/
cp /app/php/etc/php-fpm.conf.default /app/php/etc/php-fpm.conf
cp /app/php/etc/php-fpm.d/www.conf.default /app/php/etc/php-fpm.d/www.conf
vim /app/php/etc/php-fpm.d/www.conf
user = nginx
group = nginx
systemctl start php-fpm 或者 service php-fpm start
unzip wordpress-5.2.1.zip
cd wordpress
cp wp-config-sample.php wp-config.php
vim wp-config.php
define( ‘DB_NAME‘, ‘wordpress‘ );
/** MySQL database username */
define( ‘DB_USER‘, ‘wordpress‘ );
/** MySQL database password */
define( ‘DB_PASSWORD‘, ‘123456‘ );
/** MySQL hostname */
define( ‘DB_HOST‘, ‘192.168.66.106‘ );
/** Database Charset to use in creating database tables. */
define( ‘DB_CHARSET‘, ‘utf8‘ );
/** The Database Collate type. Don‘t change this if in doubt. */
define( ‘DB_COLLATE‘, ‘‘ );
systemctl start nfs
vim /etc/exports
/data/wordpress *(rw,no_root_squash)
exportfs -r
mount 192.168.66.105:/data/wordpress /apps/nginx/html/wordpress/ (在103、104机器上操作)
chown -R nginx.nginx /apps/nginx/html/wordpress/ (在103、104机器上操作)
yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boostdevel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssldevel libevent-devel libaio-devel
tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local
ln -sv mariadb-10.2.23-linux-x86_64/ mysql
chown -R root.root mysql/
useradd -r -s /sbin/nologin mysql -d /data/mysql
mkdir /data/mysql
chown mysql.mysql /data/mysql
cd mysql/
scripts/mysql_install_db --user=mysql --datadir=/data/mysql
mkdir /etc/mysql
cp support-files/my-huge.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]
datadir=/data/mysql
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin:$PATH
. /etc/profile.d/lamp.sh
service mysqld start
mysql
create database wordpress;
grant all on wordpress.* to wordpress@‘192.168.66.%‘ identified by ‘123456‘;
yum install keepalived
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id s3.pengbo.com
vrrp_skip_check_adv_addr
vrrp_iptables
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VIP2 {
state MASTER (区分主从)
interface eth0
virtual_router_id 99
priority 100 (主和从优先级要不一样)
advert_int 2
unicast_src_ip 192.168.66.107 (这个地方填写本机地址)
unicast_peer {
192.168.66.108 (这个地方填写另外一个监视地址)
}
authentication {
auth_type PASS
auth_pass linux36
}
virtual_ipaddress {
192.168.66.202 dev eth0 label eth0:0
}
}
include /etc/keepalived/conf/*.conf (导入子配置文件)
mkdir /etc/keepalived/conf
vim /etc/keepalived/conf/lvs.conf
virtual_server 192.168.66.202 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
#persistence_timeout 20
protocol TCP
sorry_server 192.168.66.105 80
real_server 192.168.66.103 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.66.104 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
systemctl start keepalived
ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.66.202:80 wrr
-> 192.168.66.103:80 Route 1 0 0
-> 192.168.66.104:80 Route 1 0 0
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
ifconfig lo:1 192.168.66.202 netmask 255.255.255.255
负载均衡haproxy+keepalived、lvs+keepalived后端php+nginx框架
标签:lamp 二进制文件 mysql pvs 打开 解压 The def protoc
原文地址:https://blog.51cto.com/14234933/2406987