k8s部署LNMP架构(wordpress)
部署WordPress LNMP架构图
一、准备nginx镜像
1.1、准备nginx镜像构建文件
[root@easzlab-images-02 nginx-base-wordpress]# ll -h total 33M drwxr-xr-x 2 root root 4.0K Aug 26 13:22 ./ drwxr-xr-x 6 root root 4.0K Aug 26 12:43 ../ -rwxr-xr-x 1 root root 163 Aug 26 12:51 build-command.sh* -rw-r--r-- 1 root root 855 Aug 26 13:21 Dockerfile -rw-r--r-- 1 root root 32M Aug 26 12:52 filebeat-7.12.1-x86_64.rpm -rw-r--r-- 1 root root 11 Aug 26 13:22 index.html -rw-r--r-- 1 root root 1.1M Aug 26 12:43 nginx-1.22.0.tar.gz -rw-r--r-- 1 root root 3.3K Aug 26 13:22 nginx.conf -rwxr-xr-x 1 root root 151 Aug 26 13:22 run_nginx.sh* [root@easzlab-images-02 nginx-base-wordpress]# cat build-command.sh #!/bin/bash TAG=$1 nerdctl build -t harbor.magedu.net/magedu/wordpress-nginx:${TAG} . nerdctl push harbor.magedu.net/magedu/wordpress-nginx:${TAG} [root@easzlab-images-02 nginx-base-wordpress]# cat Dockerfile #Nginx Base Image FROM centos:7.9.2009 ADD filebeat-7.12.1-x86_64.rpm /tmp RUN yum install -y /tmp/filebeat-7.12.1-x86_64.rpm vim wget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop && rm -rf /etc/localtime /tmp/filebeat-7.12.1-x86_64.rpm && ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && useradd nginx -u 2088 ADD nginx-1.22.0.tar.gz /usr/local/src/ RUN cd /usr/local/src/nginx-1.22.0 && ./configure --prefix=/apps/nginx && make && make install && ln -sv /apps/nginx/sbin/nginx /usr/sbin/nginx &&rm -rf /usr/local/src/nginx-1.22.0.tar.gz ADD nginx.conf /apps/nginx/conf/nginx.conf ADD run_nginx.sh /apps/nginx/sbin/run_nginx.sh RUN mkdir -pv /home/nginx/wordpress RUN chown nginx.nginx /home/nginx/wordpress/ -R EXPOSE 80 443 CMD ["/apps/nginx/sbin/run_nginx.sh"] [root@easzlab-images-02 nginx-base-wordpress]# [root@easzlab-images-02 nginx-base-wordpress]# cat run_nginx.sh #!/bin/bash /apps/nginx/sbin/nginx tail -f /etc/hosts [root@easzlab-images-02 nginx-base-wordpress]# [root@easzlab-images-02 nginx-base-wordpress]# cat nginx.conf user nginx nginx; worker_processes auto; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; client_max_body_size 10M; client_body_buffer_size 16k; client_body_temp_path /apps/nginx/tmp 1 2 2; gzip on; server { listen 80; server_name blogs.magedu.net; location / { root /home/nginx/wordpress; index index.php index.html index.htm; } location ~ \.php$ { root /home/nginx/wordpress; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
1.2、构建nginx镜像
二、准备php镜像
2.1、准备php镜像所需文件
[root@easzlab-images-02 php]# ll -h total 32M drwxr-xr-x 2 root root 4.0K Aug 26 13:39 ./ drwxr-xr-x 4 root root 4.0K Aug 26 13:08 ../ -rwxr-xr-x 1 root root 313 Aug 13 12:05 build-command.sh* -rw-r--r-- 1 root root 707 Aug 26 13:39 Dockerfile -rw-r--r-- 1 root root 32M Aug 26 13:37 filebeat-7.12.1-x86_64.rpm -rwxr-xr-x 1 root root 175 Jun 22 2021 run_php.sh* -rw-r--r-- 1 root root 19K Jun 22 2021 www.conf [root@easzlab-images-02 php]# cat build-command.sh #!/bin/bash TAG=$1 nerdctl build -t harbor.magedu.net/magedu/wordpress-php-5.6:${TAG} . nerdctl push harbor.magedu.net/magedu/wordpress-php-5.6:${TAG} [root@easzlab-images-02 php]# cat Dockerfile #PHP Base Image FROM centos:7.9.2009 ADD filebeat-7.12.1-x86_64.rpm /tmp RUN yum install -y /tmp/filebeat-7.12.1-x86_64.rpm vim wget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop && rm -rf /etc/localtime /tmp/filebeat-7.12.1-x86_64.rpm && ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && useradd nginx -u 2088 RUN yum install -y https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm && yum install php56-php-fpm php56-php-mysql -y ADD www.conf /opt/remi/php56/root/etc/php-fpm.d/www.conf ADD run_php.sh /usr/local/bin/run_php.sh EXPOSE 9000 CMD ["/usr/local/bin/run_php.sh"] [root@easzlab-images-02 php]# cat run_php.sh #!/bin/bash/opt/remi/php56/root/usr/sbin/php-fpm tail -f /etc/hosts [root@easzlab-images-02 php]# grep -Ev '^$|^;' www.conf [www] user = nginx group = nginx listen = 0.0.0.0:9000 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 slowlog = /opt/remi/php56/root/var/log/php-fpm/www-slow.log php_admin_value[error_log] = /opt/remi/php56/root/var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on php_value[session.save_handler] = files php_value[session.save_path] = /opt/remi/php56/root/var/lib/php/session php_value[soap.wsdl_cache_dir] = /opt/remi/php56/root/var/lib/php/wsdlcache [root@easzlab-images-02 php]#
www.conf完整文件
; Start a new pool named 'www'. ; the variable $pool can we used in any directive and will be replaced by the ; pool name ('www' here) [www] ; Per pool prefix ; It only applies on the following directives: ; - 'slowlog' ; - 'listen' (unixsocket) ; - 'chroot' ; - 'chdir' ; - 'php_values' ; - 'php_admin_values' ; When not set, the global prefix (or @php_fpm_prefix@) applies instead. ; Note: This directive can also be relative to the global prefix. ; Default Value: none ;prefix = /path/to/pools/$pool ; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. ; RPM: apache user chosen to provide access to the same directories as httpd user = nginx ; RPM: Keep a group allowed to write in log dir. group = nginx ; The address on which to accept FastCGI requests. ; Valid syntaxes are: ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on ; a specific port; ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on ; a specific port; ; 'port' - to listen on a TCP socket to all IPv4 addresses on a ; specific port; ; '[::]:port' - to listen on a TCP socket to all addresses ; (IPv6 and IPv4-mapped) on a specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. listen = 0.0.0.0:9000 ; Set listen(2) backlog. ; Default Value: 65535 ;listen.backlog = 65535 ; Set permissions for unix socket, if one is used. In Linux, read/write ; permissions must be set in order to allow connections from a web server. ; Default Values: user and group are set as the running user ; mode is set to 0660 ;listen.owner = nobody ;listen.group = nobody ;listen.mode = 0660 ; When POSIX Access Control Lists are supported you can set them using ; these options, value is a comma separated list of user/group names. ; When set, listen.owner and listen.group are ignored ;listen.acl_users = apache ;listen.acl_groups = ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address ; must be separated by a comma. If this value is left blank, connections will be ; accepted from any ip address. ; Default Value: any ; listen.allowed_clients = 127.0.0.1 ; Specify the nice(2) priority to apply to the pool processes (only if set) ; The value can vary from -19 (highest priority) to 20 (lower priority) ; Note: - It will only work if the FPM master process is launched as root ; - The pool processes will inherit the master process priority ; unless it specified otherwise ; Default Value: no set ; process.priority = -19 ; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user ; or group is differrent than the master process user. It allows to create process ; core dump and ptrace the process for the pool user. ; Default Value: no ; process.dumpable = yes ; Choose how the process manager will control the number of child processes. ; Possible Values: ; static - a fixed number (pm.max_children) of child processes; ; dynamic - the number of child processes are set dynamically based on the ; following directives. With this process management, there will be ; always at least 1 children. ; pm.max_children - the maximum number of children that can ; be alive at the same time. ; pm.start_servers - the number of children created on startup. ; pm.min_spare_servers - the minimum number of children in 'idle' ; state (waiting to process). If the number ; of 'idle' processes is less than this ; number then some children will be created. ; pm.max_spare_servers - the maximum number of children in 'idle' ; state (waiting to process). If the number ; of 'idle' processes is greater than this ; number then some children will be killed. ; ondemand - no children are created at startup. Children will be forked when ; new requests will connect. The following parameter are used: ; pm.max_children - the maximum number of children that ; can be alive at the same time. ; pm.process_idle_timeout - The number of seconds after which ; an idle process will be killed. ; Note: This value is mandatory. pm = dynamic ; The number of child processes to be created when pm is set to 'static' and the ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. ; This value sets the limit on the number of simultaneous requests that will be ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP ; CGI. The below defaults are based on a server without much resources. Don't ; forget to tweak pm.* to fit your needs. ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' ; Note: This value is mandatory. pm.max_children = 50 ; The number of child processes created on startup. ; Note: Used only when pm is set to 'dynamic' ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 pm.start_servers = 5 ; The desired minimum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' pm.min_spare_servers = 5 ; The desired maximum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' pm.max_spare_servers = 35 ; The number of seconds after which an idle process will be killed. ; Note: Used only when pm is set to 'ondemand' ; Default Value: 10s ;pm.process_idle_timeout = 10s; ; The number of requests each child process should execute before respawning. ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. ; Default Value: 0 ;pm.max_requests = 500 ; The URI to view the FPM status page. If this value is not set, no URI will be ; recognized as a status page. It shows the following informations: ; pool - the name of the pool; ; process manager - static, dynamic or ondemand; ; start time - the date and time FPM has started; ; start since - number of seconds since FPM has started; ; accepted conn - the number of request accepted by the pool; ; listen queue - the number of request in the queue of pending ; connections (see backlog in listen(2)); ; max listen queue - the maximum number of requests in the queue ; of pending connections since FPM has started; ; listen queue len - the size of the socket queue of pending connections; ; idle processes - the number of idle processes; ; active processes - the number of active processes; ; total processes - the number of idle + active processes; ; max active processes - the maximum number of active processes since FPM ; has started; ; max children reached - number of times, the process limit has been reached, ; when pm tries to start more children (works only for ; pm 'dynamic' and 'ondemand'); ; Value are updated in real time. ; Example output: ; pool: www ; process manager: static ; start time: 01/Jul/2011:17:53:49 +0200 ; start since: 62636 ; accepted conn: 190460 ; listen queue: 0 ; max listen queue: 1 ; listen queue len: 42 ; idle processes: 4 ; active processes: 11 ; total processes: 15 ; max active processes: 12 ; max children reached: 0 ; ; By default the status page output is formatted as text/plain. Passing either ; 'html', 'xml' or 'json' in the query string will return the corresponding ; output syntax. Example: ; http://www.foo.bar/status ; http://www.foo.bar/status?json ; http://www.foo.bar/status?html ; http://www.foo.bar/status?xml ; ; By default the status page only outputs short status. Passing 'full' in the ; query string will also return status for each pool process. ; Example: ; http://www.foo.bar/status?full ; http://www.foo.bar/status?json&full ; http://www.foo.bar/status?html&full ; http://www.foo.bar/status?xml&full ; The Full status returns for each process: ; pid - the PID of the process; ; state - the state of the process (Idle, Running, ...); ; start time - the date and time the process has started; ; start since - the number of seconds since the process has started; ; requests - the number of requests the process has served; ; request duration - the duration in ?s of the requests; ; request method - the request method (GET, POST, ...); ; request URI - the request URI with the query string; ; content length - the content length of the request (only with POST); ; user - the user (PHP_AUTH_USER) (or '-' if not set); ; script - the main script called (or '-' if not set); ; last request cpu - the %cpu the last request consumed ; it's always 0 if the process is not in Idle state ; because CPU calculation is done when the request ; processing has terminated; ; last request memory - the max amount of memory the last request consumed ; it's always 0 if the process is not in Idle state ; because memory calculation is done when the request ; processing has terminated; ; If the process is in Idle state, then informations are related to the ; last request the process has served. Otherwise informations are related to ; the current request being served. ; Example output: ; ************************ ; pid: 31330 ; state: Running ; start time: 01/Jul/2011:17:53:49 +0200 ; start since: 63087 ; requests: 12808 ; request duration: 1250261 ; request method: GET ; request URI: /test_mem.php?N=10000 ; content length: 0 ; user: - ; script: /home/fat/web/docs/php/test_mem.php ; last request cpu: 0.00 ; last request memory: 0 ; ; Note: There is a real-time FPM status monitoring sample web page available ; It's available in: @EXPANDED_DATADIR@/fpm/status.html ; ; Note: The value must start with a leading slash (/). The value can be ; anything, but it may not be a good idea to use the .php extension or it ; may conflict with a real PHP file. ; Default Value: not set ;pm.status_path = /status ; The ping URI to call the monitoring page of FPM. If this value is not set, no ; URI will be recognized as a ping page. This could be used to test from outside ; that FPM is alive and responding, or to ; - create a graph of FPM availability (rrd or such); ; - remove a server from a group if it is not responding (load balancing); ; - trigger alerts for the operating team (24/7). ; Note: The value must start with a leading slash (/). The value can be ; anything, but it may not be a good idea to use the .php extension or it ; may conflict with a real PHP file. ; Default Value: not set ;ping.path = /ping ; This directive may be used to customize the response of a ping request. The ; response is formatted as text/plain with a 200 response code. ; Default Value: pong ;ping.response = pong ; The access log file ; Default: not set ;access.log = log/$pool.access.log ; The access log format. ; The following syntax is allowed ; %%: the '%' character ; %C: %CPU used by the request ; it can accept the following format: ; - %{user}C for user CPU only ; - %{system}C for system CPU only ; - %{total}C for user + system CPU (default) ; %d: time taken to serve the request ; it can accept the following format: ; - %{seconds}d (default) ; - %{miliseconds}d ; - %{mili}d ; - %{microseconds}d ; - %{micro}d ; %e: an environment variable (same as $_ENV or $_SERVER) ; it must be associated with embraces to specify the name of the env ; variable. Some exemples: ; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e ; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e ; %f: script filename ; %l: content-length of the request (for POST request only) ; %m: request method ; %M: peak of memory allocated by PHP ; it can accept the following format: ; - %{bytes}M (default) ; - %{kilobytes}M ; - %{kilo}M ; - %{megabytes}M ; - %{mega}M ; %n: pool name ; %o: output header ; it must be associated with embraces to specify the name of the header: ; - %{Content-Type}o ; - %{X-Powered-By}o ; - %{Transfert-Encoding}o ; - .... ; %p: PID of the child that serviced the request ; %P: PID of the parent of the child that serviced the request ; %q: the query string ; %Q: the '?' character if query string exists ; %r: the request URI (without the query string, see %q and %Q) ; %R: remote IP address ; %s: status (response code) ; %t: server time the request was received ; it can accept a strftime(3) format: ; %d/%b/%Y:%H:%M:%S %z (default) ; %T: time the log has been written (the request has finished) ; it can accept a strftime(3) format: ; %d/%b/%Y:%H:%M:%S %z (default) ; %u: remote user ; ; Default: "%R - %u %t \"%m %r\" %s" ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" ; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set slowlog = /opt/remi/php56/root/var/log/php-fpm/www-slow.log ; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 ;request_slowlog_timeout = 0 ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 ;request_terminate_timeout = 0 ; Set open file descriptor rlimit. ; Default Value: system defined value ;rlimit_files = 1024 ; Set max core size rlimit. ; Possible Values: 'unlimited' or an integer greater or equal to 0 ; Default Value: system defined value ;rlimit_core = 0 ; Chroot to this directory at the start. This value must be defined as an ; absolute path. When this value is not set, chroot is not used. ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one ; of its subdirectories. If the pool prefix is not set, the global prefix ; will be used instead. ; Note: chrooting is a great security feature and should be used whenever ; possible. However, all PHP paths will be relative to the chroot ; (error_log, sessions.save_path, ...). ; Default Value: not set ;chroot = ; Chdir to this directory at the start. ; Note: relative path can be used. ; Default Value: current directory or / when chroot ;chdir = /var/www ; Redirect worker stdout and stderr into main error log. If not set, stdout and ; stderr will be redirected to /dev/null according to FastCGI specs. ; Note: on highloaded environement, this can cause some delay in the page ; process time (several ms). ; Default Value: no ;catch_workers_output = yes ; Clear environment in FPM workers ; Prevents arbitrary environment variables from reaching FPM worker processes ; by clearing the environment in workers before env vars specified in this ; pool configuration are added. ; Setting to "no" will make all environment variables available to PHP code ; via getenv(), $_ENV and $_SERVER. ; Default Value: yes ;clear_env = no ; Limits the extensions of the main script FPM will allow to parse. This can ; prevent configuration mistakes on the web server side. You should only limit ; FPM to .php extensions to prevent malicious users to use other extensions to ; exectute php code. ; Note: set an empty value to allow all extensions. ; Default Value: .php ;security.limit_extensions = .php .php3 .php4 .php5 ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from ; the current environment. ; Default Value: clean env ;env[HOSTNAME] = $HOSTNAME ;env[PATH] = /usr/local/bin:/usr/bin:/bin ;env[TMP] = /tmp ;env[TMPDIR] = /tmp ;env[TEMP] = /tmp ; Additional php.ini defines, specific to this pool of workers. These settings ; overwrite the values previously defined in the php.ini. The directives are the ; same as the PHP SAPI: ; php_value/php_flag - you can set classic ini defines which can ; be overwritten from PHP call 'ini_set'. ; php_admin_value/php_admin_flag - these directives won't be overwritten by ; PHP call 'ini_set' ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. ; Defining 'extension' will load the corresponding shared extension from ; extension_dir. Defining 'disable_functions' or 'disable_classes' will not ; overwrite previously defined php.ini values, but will append the new value ; instead. ; Note: path INI options can be relative and will be expanded with the prefix ; (pool, global or @prefix@) ; Default Value: nothing is defined by default except the values in php.ini and ; specified at startup with the -d argument ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com ;php_flag[display_errors] = off php_admin_value[error_log] = /opt/remi/php56/root/var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on ;php_admin_value[memory_limit] = 128M ; Set the following data paths to directories owned by the FPM process user. ; ; Do not change the ownership of existing system directories, if the process ; user does not have write permission, create dedicated directories for this ; purpose. ; ; See warning about choosing the location of these directories on your system ; at http://php.net/session.save-path php_value[session.save_handler] = files php_value[session.save_path] = /opt/remi/php56/root/var/lib/php/session php_value[soap.wsdl_cache_dir] = /opt/remi/php56/root/var/lib/php/wsdlcache
2.2、构建php镜像
三、准备mysql集群环境
安装部署参考:https://www.cnblogs.com/cyh00001/p/16610930.html
四、安装wordpress服务
4.1、准备wordpress部署yaml文件
[root@easzlab-images-02 php]# cat wordpress.yaml
kind: Deployment #apiVersion: extensions/v1beta1 apiVersion: apps/v1 metadata: labels: app: wordpress-app name: wordpress-app-deployment namespace: magedu spec: replicas: 1 selector: matchLabels: app: wordpress-app template: metadata: labels: app: wordpress-app spec: containers: - name: wordpress-app-nginx image: harbor.magedu.net/magedu/wordpress-nginx:v1 imagePullPolicy: Always ports: - containerPort: 80 protocol: TCP name: http - containerPort: 443 protocol: TCP name: https volumeMounts: - name: wordpress mountPath: /home/nginx/wordpress readOnly: false - name: wordpress-app-php image: harbor.magedu.net/magedu/wordpress-php-5.6:v1 #imagePullPolicy: IfNotPresent imagePullPolicy: Always ports: - containerPort: 9000 protocol: TCP name: http volumeMounts: - name: wordpress mountPath: /home/nginx/wordpress readOnly: false volumes: - name: wordpress nfs: server: 172.16.88.169 path: /nfs_share/k8sdata/magedu/wordpress --- kind: Service apiVersion: v1 metadata: labels: app: wordpress-app name: wordpress-app-spec namespace: magedu spec: type: NodePort ports: - name: http port: 80 protocol: TCP targetPort: 80 nodePort: 30031 - name: https port: 443 protocol: TCP targetPort: 443 nodePort: 30033 selector: app: wordpress-app
4.2、安装部署wordpress
4.3、验证wordpress
查看svc服务映射端口
测试是否可以正常访问
测试访问index.html静态页面
测试访问index.php
五、配置wordpress
5.1、解压并导入wordpress包
#在pod挂载的pvc存储卷所在的nfs节点机器下载wordpress [root@easzlab-k8s-nfs ~]# mkdir -p /nfs_share/k8sdata/magedu/wordpres [root@easzlab-k8s-nfs ~]# cd /nfs_share/k8sdata/magedu/wordpress [root@easzlab-k8s-nfs magedu]# wget https://cn.wordpress.org/wordpress-5.0.16-zh_CN.tar.gz [root@easzlab-k8s-nfs magedu]# tar -xf wordpress-5.0.16-zh_CN.tar.gz [root@easzlab-k8s-nfs magedu]# mv wordpress/* . [root@easzlab-k8s-nfs magedu]# cd ../ && chown -R 2088.2088 wordpress/ [root@easzlab-k8s-nfs magedu]# ll -h wordpress/ total 200K drwxr-xr-x 5 2088 2088 4.0K Aug 26 14:49 ./ drwxr-xr-x 16 root root 268 Aug 26 13:34 ../ -rw-r--r-- 1 2088 2088 418 Sep 25 2013 index.php -rw-r--r-- 1 2088 2088 20K Mar 11 05:49 license.txt -rw-r--r-- 1 2088 2088 7.3K Mar 11 05:49 readme.html -rw-r--r-- 1 2088 2088 6.8K Dec 13 2018 wp-activate.php drwxr-xr-x 9 2088 2088 4.0K Mar 11 05:40 wp-admin/ -rw-r--r-- 1 2088 2088 364 Dec 19 2015 wp-blog-header.php -rw-r--r-- 1 2088 2088 1.9K May 2 2018 wp-comments-post.php -rw-rw-rw- 1 2088 2088 3.1K Aug 26 14:49 wp-config.php -rw-r--r-- 1 2088 2088 2.8K Mar 11 05:49 wp-config-sample.php drwxr-xr-x 5 2088 2088 69 Aug 26 14:49 wp-content/ -rw-r--r-- 1 2088 2088 3.6K Aug 20 2017 wp-cron.php drwxr-xr-x 19 2088 2088 8.0K Mar 11 05:49 wp-includes/ -rw-r--r-- 1 2088 2088 2.4K Nov 21 2016 wp-links-opml.php -rw-r--r-- 1 2088 2088 3.3K Aug 22 2017 wp-load.php -rw-r--r-- 1 2088 2088 37K Dec 13 2018 wp-login.php -rw-r--r-- 1 2088 2088 7.9K Jan 11 2017 wp-mail.php -rw-r--r-- 1 2088 2088 18K Oct 23 2018 wp-settings.php -rw-r--r-- 1 2088 2088 30K Apr 29 2018 wp-signup.php -rw-r--r-- 1 2088 2088 4.6K Oct 23 2017 wp-trackback.php -rw-r--r-- 1 2088 2088 3.0K Aug 31 2016 xmlrpc.php [root@easzlab-k8s-nfs magedu]#
5.2、配置haproxy 反向代理
在3台haproxy集群节点,增加wordpress svc 端口vip域名映射,并重启haproxy服务
[root@easzlab-haproxy-keepalive-01 ~]# vi /etc/haproxy/haproxy.cfg [root@easzlab-haproxy-keepalive-01 ~]# cat /etc/haproxy/haproxy.cfg ###########全局配置######### global log 127.0.0.1 local0 log 127.0.0.1 local1 notice daemon nbproc 1 #进程数量 maxconn 4096 #最大连接数 user haproxy #运行用户 group haproxy #运行组 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid # Default SSL material locations ca-base /etc/ssl/certs crt-base /etc/ssl/private # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets ########默认配置############ defaults log global mode http #默认模式{ tcp|http|health } option httplog #日志类别,采用httplog option dontlognull #不记录健康检查日志信息 retries 2 #2次连接失败不可用 # option forwardfor #后端服务获得真实ip option httpclose #请求完毕后主动关闭http通道 option abortonclose #服务器负载很高,自动结束比较久的链接 maxconn 4096 #最大连接数 timeout connect 5m #连接超时 timeout client 1m #客户端超时 timeout server 31m #服务器超时 timeout check 10s #心跳检测超时 balance roundrobin #负载均衡方式,轮询 ########统计页面配置######## listen stats bind 172.16.88.200:1080 mode http option httplog log 127.0.0.1 local0 err maxconn 10 #最大连接数 stats refresh 30s stats uri /admin #状态页面 http//ip:1080/admin访问 stats realm Haproxy\ Statistics stats auth admin:admin #用户和密码:admin stats hide-version #隐藏版本信息 stats admin if TRUE #设置手工启动/禁用 #############K8S############### listen k8s_api_nodes_6443 bind 172.16.88.200:6443 mode tcp server easzlab-k8s-master-01 172.16.88.154:6443 check inter 2000 fall 3 rise 5 server easzlab-k8s-master-02 172.16.88.155:6443 check inter 2000 fall 3 rise 5 server easzlab-k8s-master-03 172.16.88.156:6443 check inter 2000 fall 3 rise 5 listen my-wordpress-80 bind 172.16.88.200:80 mode tcp server easzlab-k8s-master-01 172.16.88.154:30031 check inter 2000 fall 3 rise 5 server easzlab-k8s-master-02 172.16.88.155:30031 check inter 2000 fall 3 rise 5 server easzlab-k8s-master-03 172.16.88.156:30031 check inter 2000 fall 3 rise 5 [root@easzlab-haproxy-keepalive-01 ~]# systemctl restart haproxy #重启haproxy服务
验证haproxy页面,检查wordpress新增配置项是否生效
5.3、增加本地hosts域名解析
测试通过域名能否访问正常
5.4、wordpress账号授权
在mysql集群mysql-0主库创建wordpress库,以及相关账号密码并授权
create database wordpress; grant all privileges on wordpress.* to "wordpress"@"%" identified by "wordpress"; flush privileges;
测试指定wordpress账号访问是否可以正常访问
5.5、获取mysql-0域名解析
查看mysql-0 dns域名
启动运行centos7 pod镜像
kubectl run net-test1 --image=harbor.magedu.net/baseimages/magedu-centos-base:7.9.2009 sleep 10000000 -n magedu
登录pod 通过ping 测试mysql pod 域名mysql-0.mysql.magedu.svc.magedu.local能否正常解析
5.6、配置wordpress
登录账号密码: admin oA^EkAEVG$Fe#8%Yi!
5.7、验证mysql主从数据
mysql-0主库
mysql-1从库
mysql-2从库
5.8、登录访问wordpress