yum -y install nfs-utils rpcbind
##安裝nfs服務和RPC服務
vim /etc/exports #nfs的配置文件
/data/v1 10.1.1.0/24(rw,no_root_squash,no_all_squash,sync)
#給10.1.1.0/24網段的ip 訪問的權限
php
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /usr/share/nginx/html; #nginx根文件地址,訪問的資源都在這個文件夾裏找 index index.html index.htm; } location ~ \.php$ { root /usr/share/nginx/html; #根文件地址,定義的nginx的根同樣便可,同時這個地址也要和nignx同樣有訪問文件。 fastcgi_pass php.default.svc.cluster.local:9000; #訪問後端php的地址,用內部server的dns解析,pod怎麼重啓都能正常訪問的到 include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; } }
3.PHP配置文件"www.conf"
listen = 0.0.0.0:9000
#監聽全部IPhtml
4.編寫nginx的yaml 資源文件 nginx-php.yamlnode
apiVersion: v1 kind: Service metadata: name: nginx-php namespace: default spec: type: NodePort #定義類型爲NodePort,用戶須要訪問經過node節點的30081 selector: app: web ports: - port: 80 #service端口 targetPort: 80 #容器端口 nodePort: 30081 #node端口,若是是ClusterIP的這段不須要,也能夠不填會隨機 --- apiVersion: v1 kind: Pod metadata: name: ngingx-php labels: app: web spec: containers: - name: ngingx-php image: nginx imagePullPolicy: IfNotPresent volumeMounts: - name: nginx-data #調用存儲卷,映射到"/usr/share/nginx/html"文件夾,這裏面是放nginx的訪問文件的 mountPath: /usr/share/nginx/html - name: nginx-conf #調用存儲卷,映射到"/etc/nginx/conf.d"文件夾,這裏面是放nginx的配置文件的 mountPath: /etc/nginx/conf.d volumes: - name: nginx-data #定義Nginx訪問文件存儲卷 nfs: path: /data/v1/data server: 10.1.1.111 #存儲卷是由nfs服務器10.1.1.111 提供的,"/data/v1/data"這個文件夾是真正存文件的 - name: nginx-conf #定義Nginx配置文件存儲卷 nfs: path: /data/v1/nginx-conf server: 10.1.1.111
5.php yaml文件 php.yamlnginx
apiVersion: v1 kind: Service metadata: name: php namespace: default spec: selector: app: php ports: - port: 9000 targetPort: 9000 #因爲nginx和php都是pod 內部訪問就能夠了暴露內部端口便可 --- apiVersion: v1 kind: Pod metadata: name: php labels: app: php spec: containers: - name: php image: phpdockerio/php56-fpm imagePullPolicy: IfNotPresent volumeMounts: - name: php-conf #調用php配置存儲卷 mountPath: /etc/php5/fpm/pool.d - name: php-data #調用nginx的存儲文件夾,php也要一份nginx的訪問文件,沒有調用過來是無文件處理 mountPath: /usr/share/nginx/html volumes: - name: php-conf nfs: path: /data/v1/php-conf server: 10.1.1.111 - name: php-data nfs: path: /data/v1/data server: 10.1.1.111
6.php 測試文件 "info.php"web
<?php phpinfo(); ?>
7.訪問
#找個node 的 30081端口訪問 http://10.1.1.111:30081/info.php docker