[root@localhost ~]# yum install mariadb mariadb-server -y
[root@localhost ~]# vim /etc/my.cnf [mysqld] server_id=1 #主id號 log_bin=/data/binlog/bin #開啓二進制日誌記錄並指定保存路徑 innodb_file_per_table #每一個表保存在單個文件 datadir=/var/lib/mysql #數據可路徑 socket=/var/lib/mysql/mysql.sock #套接字路徑 ……
[root@localhost ~]# systemctl start mariadb [root@localhost ~]# mysql -uroot -h127.0.0.1 添加從服務受權用戶: MariaDB [(none)]> grant replication slave on *.* to user1@'192.168.1.106' identified by '123456'; 建立wordpress專用數據庫: MariaDB [(none)]> create database boss; 添加wordpress受權用戶: MariaDB [(none)]> grant all on boss.* to boss@'192.168.1.%' identified by '123456';
[mysqld] server_id=2 #從服務的id號 read_only #只讀模式不容許修改數據內容 innodb_file_per_table datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock …..
[root@localhost ~]# systemctl start mariadb [root@localhost ~]# msyql MariaDB [(none)]> change master to master_host='192.168.1.9', master_user='user1', master_password='123456', master_log_file='bin.000005', master_log_pos=245; MariaDB [(none)]> start slave;#開啓從服務 MariaDB [(none)]>show slave status\G; #查看主從創建狀態 lave_IO_State: Waiting for master to send event Master_Host: 192.168.1.9 Master_User: user1 Master_Port: 3306 Connect_Retry: 60 Master_Log_File: bin.000007 Read_Master_Log_Pos: 245 Relay_Log_File: mariadb-relay-bin.000007 Relay_Log_Pos: 523 Relay_Master_Log_File: bin.000007 Slave_IO_Running: Yes Slave_SQL_Running: Yes …… ……
[root@localhost ~]# yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools vim iotop bc zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate
[root@localhost ~]# tar xvf /data/tools/haproxy/haproxy-1.8.20.tar.gz -C /data/tools/haproxy/haproxy/ [root@localhost ~]# cd /data/tools/haproxy/haproxy-1.8.20 [root@localhost haproxy-1.8.20]# 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 編譯註釋: ARCH=x86_64:x86_64平臺 TARGET=linux2628: linux的內核版本爲 2.6.28, 3.x及以上版本 USE_PCRE=1 :支持正則表達 USE_ZLIB=1 :支持壓縮 USE_SYSTEMD=1:支持systemd啓動服務管理 USE_CPU_AFFINITY=1:CUP核心綁定 PREFIX=/usr/local/haproxy:安裝路徑 [root@localhost haproxy-1.8.20]# make install PREFIX=/usr/local/haproxy
[root@localhost haproxy-1.8.20]# cp haproxy /usr/sbin/
[root@localhost haproxy-1.8.20]# vim /usr/lib/systemd/system/haproxy.service [Unit] Description=HAproxy Load Balancer 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 ExecStop=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target
[root@localhost ~]# useradd -r -s /sbin/nologin haproxy -u 88 [root@localhost ~]# groupmod -g 88 haproxy
[root@localhost ~]# vim /etc/haproxy/haproxy.cfg …… uid 88 #執行haproxy的用戶身份 gid 88 #所屬的組 …… listen webpro bind 192.168.1.23:80 #綁定虛擬VIP及端口 mode tcp server web1 192.168.1.108:80 #綁定nginx後端服務 server web2 192.168.1.109:80 #綁定nginx後端服務 listen mysql_3306 bind 192.168.1.23:3306 mode tcp server web3 192.168.1.9:3306 #綁定mysql數據庫
[root@localhost ~]# systemctl start haproxy
[root@localhost ~]# yum install keepalived -y
! 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 192.168.200.1 smtp_connect_timeout 30 router_id s1 vrrp_skip_check_adv_addr #vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_instance VIP1 { state MASTER #另一臺主機改成BACKUP interface ens33 virtual_router_id 23 priority 100 #另一臺備份服務優先級改成80,要不比100低 advert_int 2 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.23 dev ens33 label ens33:0 } unicast_src_ip 192.168.1.110 #另一臺備份服務的單播 ip位置與master的ip位置對調 unicast_peer { 192.168.1.107 } }
[root@localhost ~]# systemctl start keepalived
[root@localhost tools]# tar xvf nginx-1.14.2.tar.gz [root@localhost tools]# cd nginx-1.14.2/
[root@localhost nginx-1.14.2]# yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed 若出現如下不能解決依賴包關係,須要配置yum倉庫,需添加update下載倉庫
[root@localhost nginx-1.14.2]# vim /etc/yum.repos.d/base.repo …… …… [update] name=aliyun_centos_update baseurl=https://mirrors.aliyun.com/centos/7.6.1810/updates/x86_64/ gpgcheck=0
[root@localhost nginx-1.14.2]# ./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 --with--http_perl_module [root@localhost nginx-1.14.2]# make&&make install
[root@centos7 ~]# useradd -r -s /sbin/nologin nginx -u 23
[root@centos7 ~]#vim /usr/lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/apps/nginx/logs/nginx.pid # Nginx will fail to start if /run/nginx.pid already exists but has the wrong # SELinux context. This might happen when running `nginx -t` from the cmdline. https://bugzilla.redhat.com/show_bug.cgi?id=1268621 ExecStartPre=/usr/bin/rm -f /apps/nginx/logs/nginx.pid ExecStartPre=/apps/nginx/sbin/nginx -t ExecStart=/apps/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID #KillSignal=SIGQUIT #TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target
[root@centos7 ~]#systemctl start nginx [root@centos7 ~]#systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2019-06-12 10:57:07 CST; 1s ago Process: 8875 ExecStart=/apps/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
[root@centos7 ~]#yum install libxml2-devel bzip2-devel libmcrypt-devel
[root@centos7 ~]#cd /data/php [root@centos7 php]# tar xvf php-7.3.2.tar.xz
[root@centos7 php]# cd php-7.3.5/ [root@centos7 php-7.3.2]# ./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 [root@centos7 php-7.3.2]# make && make install
主配置:/app/php/etc/php-fpm.conf 子配置:/app/php/etc/php-fpm.d/ www.conf 修改時區配置文件: /etc/php.ini 腳本文件:/etc/init.d/php-fpm [root@centos7 php-7.3.2]# cp php.ini-production /etc/php.ini [root@centos7 php-7.3.2]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@centos7 php-7.3.2]# chmod +x /etc/init.d/php-fpm #腳本文件添加執行權限 [root@centos7 php-7.3.2]# cd /app/php/etc/ [root@centos7 etc]# cp php-fpm.conf.default php-fpm.conf #主配置文件不須要修改 [root@centos7 etc]# cd /app/php/etc/php-fpm.d/ #修改子配置文件 [root@centos7 php-fpm.d]# cp www.conf.default www.conf [root@centos7 php-fpm.d]# vim www.conf user = nginx #進程啓動用戶爲nginx group =nginx #屬組爲nginx組 listen = 127.0.0.1:9000 #監聽本地9000端口
[root@centos7 php-fpm.d]# service php-fpm start
[root@centos7 tools]# tar xvf wordpress-5.0.3-zh_CN.tar.gz -C /apps/nginx/html/
[root@centos7 html]# chown -R nginx.nginx wordpress/
[root@centos7 wordpress]#cp wp-config-sample.php wp-config.php [root@centos7 wordpress]#vim wp-config.php // ** MySQL 設置 - 具體信息來自您正在使用的主機 ** // /** WordPress數據庫的名稱 */ define('DB_NAME', 'boss'); /** MySQL數據庫用戶名 */ define('DB_USER', 'boss'); /** MySQL數據庫密碼 */ define('DB_PASSWORD', '123456'); /** MySQL主機 */ define('DB_HOST', '192.168.1.23'); #虛擬VIP /** 建立數據表時默認的文字編碼 */ define('DB_CHARSET', 'utf8'); /** 數據庫整理類型。如不肯定請勿更改 */ define('DB_COLLATE', ''); …… ……
[root@centos7 html]# scp -p -r wordpress/* 192.168.1.109:/apps/nginx/html/
[root@centos7 html]#vim /apps/nginx/conf/nginx.conf …… location / { root html/wordpress; index index.php index.html index.htm; } location ~ \.php$ { root /apps/nginx/html/wordpress; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } …… [root@centos7 html]# systemctl restart nginx
[root@localhost ~]# yum install nfs-utils -y
[root@localhost ~]# vim /etc/exports /data/NFS/ 192.168.1.108(rw,no_root_squash) 192.168.1.109(rw,no_root_squash)
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# exportfs -v /data/NFS 192.168.1.108(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash) /data/NFS 192.168.1.109(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
mount 192.168.1.101/data/NFS /apps/nginx/html/wordpress/wp-content/uploads