Install Haproxy # yum -y update # yum install haproxy openssl-devel # nano -w /etc/haproxy/haproxy.cfg #---------------------------------------------------------------------# Example configuration for a possible web application. See the# full configuration options online.## http://haproxy.1wt.eu/download/1.4/doc/configuration.txt##---------------------------------------------------------------------#---------------------------------------------------------------------# Global settings#---------------------------------------------------------------------global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats#---------------------------------------------------------------------# common defaults that all the 'listen' and 'backend' sections will# use if not designated in their block#---------------------------------------------------------------------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 3000#---------------------------------------------------------------------# main frontend which proxys to the backends#---------------------------------------------------------------------#frontend main *:5000# acl url_static path_beg -i /static /images /javascript /stylesheets# acl url_static path_end -i .jpg .gif .png .css .js## use_backend static if url_static# default_backend appfrontend LB bind *:80 reqadd X-Forwarded-Proto:\ http default_backend LB#---------------------------------------------------------------------# static backend for serving up images, stylesheets and such#---------------------------------------------------------------------#backend static# balance roundrobin# server static 127.0.0.1:4331 check##---------------------------------------------------------------------# round robin balancing between the various backends#---------------------------------------------------------------------#backend app# balance roundrobin# server webserv1 203.78.98.153:80 check# server webserv2 203.78.98.158:80 checkbackend LB *:80 mode http stats enable stats hide-version stats uri /stats stats realm Haproxy\ Statistics stats auth haproxy:redhat # Credentials for HAProxy Statistic report page. balance roundrobin # Load balancing will work in round-robin process. option httpchk option httpclose option forwardfor cookie LB insert server webserv1 203.78.98.153:80 cookie webserv1 check # backend server. server webserv2 203.78.98.158:80 cookie webserv2 check # backend server. # systemctl enable haproxy.service # systemctl restart haproxy.service Config Log Haproxy # nano -w /etc/rsyslog.conf # Provides UDP syslog reception$ModLoad imudp$UDPServerRun 51 # nano -w /etc/rsyslog.d/haproxy.conf local2.* /var/log/haproxy.log # systemctl restart rsyslog.service Install Csf # cd /usr/src # wget https://download.configserver.com/csf.tgz # tar -xzf csf.tgz # cd csf # sh install.sh # nano -w /etc/csf/csf.conf # csf -r # yum install perl-libwww-perl net-tools perl-LWP-Protocol-https -y Enabling SSL in HAProxy # yum install mod_ssl -y # cd /etc/ssl/ # openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/balance.key -out /etc/ssl/balance.crt # cat balance.crt balance.key > balance.pem # nano -w /etc/haproxy/haproxy.cfg # main frontend which proxys to the backendsfrontend LBS bind *:443 ssl crt /etc/ssl/balance.pem reqadd X-Forwarded-Proto:\ https default_backend LB# static backend for serving up images, stylesheets and suchredirect scheme https if !{ ssl_fc } # systemctl restart haproxy Install Zabbix-agent # mkdir -p /etc/zabbix# rpm -Uvh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm# yum install zabbix-agent -y# cd /etc/zabbix# mv zabbix_agentd.conf zabbix_agentd.conf.bak # wget http://siaminterhost.com/zabbix_agentd/zabbix_agentd.conf# systemctl start zabbix-agent# systemctl enable zabbix-agent Allow Port 10050-10051
Config Webserver # yum update -y Disable Selinux # nano -w /etc/selinux/config Install Csf firewall # cd /usr/src# wget https://download.configserver.com/csf.tgz# tar -xzf csf.tgz# cd csf/# sh install.sh # yum install perl-libwww-perl net-tools perl-LWP-Protocol-https -y# csf -r Install httpd # yum install httpd # systemctl enable httpd# systemctl start httpd Install PHP 5.6 # yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm# yum install yum-utils # yum-config-manager --enable remi-php56# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo Install Mysql 5.7 # yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm# yum install mysql-community-server# systemctl enable mysqld# systemctl start mysqld# systemctl status mysqld Test Connection remote Database # mysql -u (user) -h (hostdatabase) (database) -p Change Directory files (var/www/html) # mkdir -p /data/www# cd /data/www/# ls -laZ /data/www# chcon -Rv --reference=/var/www/html /data/www# chcon -t httpd_sys_content_t /data/www/ -R# chcon -t httpd_sys_rw_content_t /data/www/ -R# chcon -R system_u:object_r:httpd_sys_content_t /data/www/# chcon -Rv --reference=/tmp /data/www # chcon -R --type=httpd_sys_rw_content_t /data/www# restorecon -Rv /data/www Install Unison (rsync) # yum install ocaml ocaml-camlp4-devel ctags ctags-etags# wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.48.4.tar.gz# tar xvzf unison-2.48.4.tar.gz # cd src/# make# cp -v unison /usr/local/sbin/# cp -v unison /usr/bin/ Test Connection # unison -testServer /data/www ssh://203.78.98.158//data/www Unsion authorized_keys # ssh-keygen -t dsa# nano -w /etc/hosts 203.78.98.153 webserv1203.78.98.158 webserv2 # scp ~/.ssh/id_dsa.pub root@203.78.98.158:.ssh/authorized_keys # nano -w /root/sync.data.sh #!/bin/bash# set paths / dirs#_paths="/data/www/ \#/data/www/ "#sync only webserv1 for now _paths="/data/www/ "# binary file name _unison=/usr/bin/unison# server names# sync webserv1.systemnetway.com with rest of the server in cluster# i.e _rserver="webserv2.systemnetway.com" _rserver="root@webserv2"# sync it for r in ${_rserver} do for p in ${_paths} do ${_unison} -batch "${p}" "ssh://${r}/${p}" done # crontab -e*/3 * * * * ./sync.data.sh &>/tmp/sync.data.sh.log Install Redis Client # yum install php-pecl-redis# service httpd graceful# php -m |grep redis# nano -w /etc/httpd/conf.d/php.conf #php_value session.save_handler "files"#php_value session.save_path "/var/lib/php/session"#php_value soap.wsdl_cache_dir "/var/lib/php/wsdlcache"php_value session.save_handler "redis"php_value session.save_path "tcp://172.168.100.6:6379?auth=vkoomN1234"php_value soap.wsdl_cache_dir "tcp://172.168.100.6:6379?auth=vkoomN1234" # cd /data/www/# nano -w test-sessions.php Created a session # nano -w /etc/csf/csf.conf Allow port 6379# csf -r# nano -w /etc/php.ini [Session]; Handler used to store/retrieve data.; http://php.net/session.save-handler;session.save_handler = filessession.save_handler = redis ;session.save_path = "/tmp"session.save_path = "tcp://172.168.100.6:6379?auth=vkoomN1234"
Install Mysql 5.7 # yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm# yum install mysql-community-server# systemctl enable mysqld# systemctl start mysqld# systemctl status mysqld# grep 'temporary password' /var/log/mysqld.log# mysql_secure_installation# mysql -u root -p Install PHP 5.6 # yum install epel-release -y # yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm# yum install yum-utils# yum-config-manager --enable remi-php56# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo Install Phpmysqladmin # yum -y install phpmyadmin# yum -y install php php-common php-mbstring php-gd Install Csf # cd /usr/src # wget https://download.configserver.com/csf.tgz# tar -xzf csf.tgz# cd csf# sh install.sh# nano -w /etc/csf/csf.conf # yum install perl-libwww-perl net-tools perl-LWP-Protocol-https -y Install Redis server # yum install redis# systemctl enable redis# systemctl start redis.service # redis-cli pingPONG # nano -w /etc/redis.conf #bind 172.168.100.6unixsocket /var/run/redis/redis.sockunixsocketperm 777 # requirepass foobared requirepass vkoomN1234 (Password ในการ auth) save 900 1save 300 10save 60 10000## Set the max memorymaxmemory 2048mb (ปรับเท่าขนาด memory ที่ใช้)## Update the eviction policymaxmemory-policy allkeys-lru # mkdir -p /var/run/redis# chown redis:redis /var/run/redis # nano -w /etc/sysctl.conf vm.overcommit_memory = 1 # sysctl -p
การทำงานของ Webserver นั้นจะทำงานเป็น Replica Data ในระดับ Realtime โดยที่มีการใช้งานหรืออัพเดทข้อมูลเครื่องใดเครื่องหนึ่ง อีกเครื่องจะทำการอัพเดทข้อมูลไปด้วย Replica Mirror แบ่งเป็นเส้นทางในการทำงานนั้นเป็น 2 ประเภทดังนี้ One Way สามารถส่งไปอย่างเดียวและแก้ไขข้อมูลได้ที่เครื่องเดียวเท่านั้น Two Way สามารถส่งไปและแก้ไขได้ทั้ง 2 เครื่อง ข้อมูลจะทำการอัพเดททั้ง 2 เครื่อง Replica Mirror ในระดับการทำงานนั้นจะมีอยู่ 3 ประเภท ดังนี้ Replica Mirror Directory Replica Mirror Partition Replica Mirror Disk 1.Replica Mirror ในระบบดับ Master Directory >>>>>>>> Slave Directory One way เป็นการทำงานของ Mirror จาก เครื่อง Mirror Master ไปยัง Mirror Client ทางเดียว สามารถเลือก Directory ที่จะไม่ทำการ Replication ได้ เมื่อ Delete ไฟล์ที่เครื่องที่เป็น Mirror Client เครื่อง Mirror Master จะไม่ถูกลบด้วย การส่ง tranfer ข้อมูลนั้นเข้ารหัส Authorized_keys 2.Replica Mirror ระดับ Partition เป็นการทำงานที่ทำการ Replica ในระบบดับ Master Partition to Slave Partition เช่น /home >>>>> /home เป็นต้น 3.Replica Mirror ระดับ Disk เป็นการทำงานโดยการ Replica ในระดับ Master Disk to Slave Disk เช่น /dev/sbd >>>>> /dev/sbd เป็นต้น ข้อมูล Update Real-time นั้นจะมีการเปลื่ยนเป็นอย่างไรนั้น ได้ทำการยกตัวอย่าง 3 ข้อด้านล่างให้เห็นถึงการทำงานของ Mirror 1.การเปลื่ยนแปลงการ Update Software ของทางโปรแกรมเมอร์ ในระดับ Real-time 2.การเปลื่ยนแปลงจากการไม่นำข้อมูลต่างๆ เช่น Log หรือข้อมูลที่ไม่เกี่ยวข้องมาใช้งาน 3.การเปลื่ยนแปลงจาก User ได้มีการ Update ข้อมูลต่างๆ เข้ามาเช่น มีการอัพเดทไฟล์รูปภาพ แก้ไข Code เป็นต้น __________________________________________________________________________________________________ Netway Communication ให้บริการด้าน Load Balancer พื้นฐานสำหรับธุรกิจ เป็นตัวแทนแบรนด์ไอทีชั้นนำมากมาย Office 365, Google Workspace, Zendesk, SSL ฯลฯ เรามีเจ้าหน้าที่พร้อมดูแลคุณ 24 ชม. ติดต่อเราเพื่อสอบถามผลิตภัณฑ์ ขอราคา หรือปรึกษาเรื่องไอที ได้เลยค่ะ Line : @netway (มี @ ด้านหน้า) หรือ https://bit.ly/line-netway Facebook : m.me/netway.offcial Tel : 02-055-1095 Email : support@netway.co.th Web Chat : https://netway.co.th/ #ให้เราช่วยคุณเรื่องไอที #การสื่อสาร Netway #มีครบจบที่เดียว #Netway Communication #NetwayTraining #NetwayConnect #Load Balancer
วิธีการตั้งค่าใช้งานเบื้องต้น1. ทำการแก้ไขไฟล์ที่ nano -w /etc/haproxy/haproxy.cfg2. เลื่อนลงมาข้างล่างสุดเพื่อทำการแก้ไข Host และ IP เครื่องเว็บเซิร์ฟเวอร์ที่จะทำ Loadbalancer3. ตัวอย่างการใส่ค่า server {Host} {IP:Port} cookie {Host} checkแทนเครื่องเว็บเซิร์ฟเวอร์เครื่องที่ 1 server webserv1 203.78.98.153:80 cookie webserv1 check # backend server แทนเครื่องเว็บเซิร์ฟเวอร์เครื่องที่ 2 server webserv2 203.78.98.158:80 cookie webserv2 check # backend serverกรณีที่เรามีเครื่องเว็บเซิร์ฟเวอร์มากกว่า 2 เครื่องก็สามารถใส่เพิ่มเข้าไปได้เลย 4.ทำการ save และ ทำการ restart service haproxy systemctl restart haproxy.service __________________________________________________________________________________________________ Netway Communication ให้บริการด้าน Load Balancer พื้นฐานสำหรับธุรกิจ เป็นตัวแทนแบรนด์ไอทีชั้นนำมากมาย Office 365, Google Workspace, Zendesk, SSL ฯลฯ เรามีเจ้าหน้าที่พร้อมดูแลคุณ 24 ชม. ติดต่อเราเพื่อสอบถามผลิตภัณฑ์ ขอราคา หรือปรึกษาเรื่องไอที ได้เลยค่ะ Line : @netway (มี @ ด้านหน้า) หรือ https://bit.ly/line-netway Facebook : m.me/netway.offcial Tel : 02-055-1095 Email : support@netway.co.th Web Chat : https://netway.co.th/ #ให้เราช่วยคุณเรื่องไอที #การสื่อสาร Netway #มีครบจบที่เดียว #Netway Communication #NetwayTraining #NetwayConnect #Load Balancer