In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to use k8s cluster in PHP environment, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
1. Download wordpresswget https://cn.wordpress.org/latest-zh_CN.zip replication code 2, create database (database I downloaded using yum, database should not be deployed in K8s cluster as far as possible) create database wordpress DEFAULT CHARACTER SET utf8;grant all on wordpress.* to 'wordpress'@'%' identified by' 123456' Copy code 3, put wordpress code into NAS storage mkdir / data-pmount-t nfs-o vers=4,minorversion=0,noresvport 12XXXXXXXxx.cn-hongkong.nas.aliyuncs.com:/ / datamv wordpress / data/ copy code 3, write dockerfile and build image (I wrote the nginx image myself, mounting configuration or using secret method can also change configuration) mkdir-p Dockerfile [root@k8s-m Dockerfile] # cat default.conf server {listen 80; server_name localhost Location / {root / usr/share/nginx/html; index index.html index.htm;} error_page 500 502 503 504 / 50x.html; location = / 50x.html {root / usr/share/nginx/html;} location ~\ .php$ {root / var/www/html; fastcgi_pass php-svc.default.svc.cluster.local:9000; fastcgi_index index.php Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}} [root@k8s-m Dockerfile] # cat Dockerfile FROM nginx:1.15.4-alpineLABEL maintainer= "zhang 1232@qq.com" COPY default.conf / etc/nginx/conf.d/EXPOSE 80CMD ["nginx", "- g", "daemon off" "] # build an image (if there is no image repository To import the image to another server) [root@k8s-m Dockerfile] # docker build-t mynginx:2.0. / # View the image [root@k8s-m Dockerfile] # docker images | grep mynginxmynginx 2.0 2fd9a2724422 2 hours ago 17.7MB copy code 4, configure nginx and php1, Create and import svc and deployments of php [root @ k8s-m ~] # cat php.yamlapiVersion: v1kind: Servicemetadata: name: php-svcspec: selector: name: php ports:-port: 9000 name: http-php targetPort: 9000 protocol: TCP-apiVersion: apps/v1kind: Deploymentmetadata: name: my-php-deployspec: replicas: 3 selector: matchLabels: name: php template: metadata: labels: name: php spec : containers:-name: php image: php:7.2-fpm ports:-name: http-php containerPort: 9000 volumeMounts:-name: php-code mountPath: / var/www/html/ volumes:-name: php-code nfs: path: / wordpress/ server: 12xxxxxxxxx.cn-hongkong.nas.aliyuncs.com copy code 2, Create and import svc and deployments of nginx [root @ k8s-m ~] # cat nginx-deploy.yamlapiVersion: v1kind: Servicemetadata: name: nginx-svcspec: selector: name: nginx ports:-port: 80 name: http targetPort: 80 protocol: TCP-apiVersion: apps/v1kind: Deploymentmetadata: name: my-nginx-deployspec: replicas: 3 selector: matchLabels: name: nginx template: metadata: labels: name : nginx spec: containers:-name: nginx image: mynginx:2.0 imagePullPolicy: IfNotPresent ports:-name: http containerPort: 80 volumeMounts:-name: html mountPath: / usr/share/nginx/html/ volumes:-name: html nfs: path: / wordpress/ server: 124xxxxxxxxxxxxx -hongkong.nas.aliyuncs.com copy code 3, Check out [root@k8s-m ~] # kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEkubernetes ClusterIP 10.96.0.1 none 443/TCP 4h25mnginx-svc ClusterIP 10.101.81.167 none 80/TCP 99mphp-svc ClusterIP 10.111.89.228 none 9000/TCP 99m [root@k8s-m ~] # kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGEmy-nginx-deploy 3ax 3 3 3 99mmy-php-deploy 3max 3 3 100m copy code 4, Create Ingress access [root@k8s-m ~] # cat wordpress-ingress.yaml apiVersion: extensions/v1beta1kind: Ingressmetadata: name: ingress-nginxspec: rules:-host: .zhang.com http: paths:-backend: serviceName: nginx-svc servicePort: 80 [root@k8s-m ~] # kubectl apply-f wordpress-ingress.yaml ingress.extensions/ingress-nginx created copy code 5, access test
5. Installation of PHP extension
Ini extension file path in the php container: / usr/local/etc/php/conf.d/
1. Enter [root@node1 ~] # docker run-it-- name php-gd php:7.2-fpm bash copy code 2 in the php container, download copy code depending on apt-get update & & apt-get install libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng-dev-y, install extensions (such as GD), install docker-php-ext-install gd#, install docker-php-ext-enable gd replication code 4, Save the container as a new image [root@node1 ~] # docker commit-p php-gd php-gd:1.0sha256:c562ad539630b3c5eb6888f0b7bac937d9d3af1d39de118106c5e6ca30a02ebd [root@node1 ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEphp-gd 1.0 c562ad539630 4 seconds ago 426MB copy code 5, Run the new php container to test [root@node1] # docker run-it-- rm php-gd:1.0 bash root@9e7fa8e57db7:/var/www/html# ls / usr/local/etc/php/conf.d/docker-php-ext-gd.ini / usr/local/etc/php/conf.d/docker-php-ext-gd.iniroot@9e7fa8e57db7:/var/www/html# cat / usr/local/etc/php/conf.d/docker-php-ext-gd.ini Extension=gd.soroot@9e7fa8e57db7:/var/www/html# php-m | grep gdgd copy code 6. Extensions such as redis install curl-L-o redis-4.1.1.tar.gz https://github.com/phpredis/phpredis/archive/4.1.1.tar.gztar xf redis-4.1.1.tar.gz rm redis-4.1.1.tar.gz mv phpredis-4.1.1 / usr/src/php/ext/redisdocker-php-ext-configure redisdocker-php-ext-install redisdocker-php-ext-enable redis copy code
# # View
Root@9d5d4e093dbd:/var/www/html# php-m | grep redisredis the above is how to use K8s cluster in PHP environment. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.