背景:测试主机是在金山云公有云平台上申请的一台Centos7.6云主机,因为发现使用云主机来做测试相当方便,而且充分利用金山云云主机的优势--弹性计费、关机不收费(此处免费广告)。总之,个人觉得还是在公有云上测试确实比wokrstation要方便很多。 1、申请金山云云主机,这一步就直接跳过了,都是下一步下一步就可以,申请一台linux云主机只需要10s就可以了 (个人配置:2C4G100g,5M-EIP) 2、远程ssh登录云主机,建议修改为非标端口或使用密钥登录,增加安全性,毕竟是在公网上。。。。 3、配置yum源,公有云主机都是带有repo配置的,当然也可以根据自己需求来配置repo yum源(推荐使用国内,都懂的),此次实验使用aliyun repo: #curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 4、下面开始安装 #yum install -y docker ----安装docker #systemctl start docker ----启动docker #systemctl enable docker ----设置docker服务开机自启动 #systemctl status docker 5、拉取centos镜像,拉取官方的就可以 #docker image pull centos #docker images 6、创建容器(我使用的是centos6.9镜像) #docker run -it -p 567:80 centos:6.9 /bin/bash ----创建容器,并进入容器 7、配置下容器的yum源 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo 8、安装nginx+php,等待安装完成 yum install -y nginx php-fpm php-gd php-mbstring unzip 9、启动nginx服务,并测试可以正常访问 #service nginx start 10、修改PHP配置文件 #vi /etc/php-fpm.d/www.conf listen = 127.0.0.1:9000 user = nginx group = nginx #grep -Ev '^$|#' /etc/nginx/nginx.conf.default > /etc/nginx/nginx.conf ----配置nginx.conf文件 #vi /etc/nginx/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /html; index index.php index.html index.htm; } location ~ .php$ { root /html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }

}

} #mkdir /html ----创建站点目录 #vi /html/info.php ---创建info.php文件,测试php服务 <?php phpinfo(); ?> #service php-fpm start -----启动php-fpm服务 #nginx -t -----测试nginx语法 浏览器打开:http://ip:端口/info.php 测试成功!!!!! 11、下载应用文件到站点目录/html下,应用文件我是放在金山云的ks3上,可以直接下载 #unzip tt.zip -----解压应用文件 #chown -R nginx:nginx /html -----修改文件属主 12、在写一个脚本文件,就可以把容器打包成镜像,以后可以随时测试啦 vi /init.sh #!/bin/bash service php-fpm start nginx -g 'daemon off;' 13、搞定收工