设为首页 收藏本站
查看: 1453|回复: 0

[经验分享] 某互联网企业技术发展史(三)安装与初步配置nginx、php fastcgi和squid

[复制链接]

尚未签到

发表于 2018-12-28 10:19:05 | 显示全部楼层 |阅读模式
今天开始安装php和nginx,以及squid,目的是访问首先通过squid缓存,未缓存则转到nginx,若为php则转到php解析器进行解析,php采用fastcgi启动方式,并使用php-fpm php fastcgi管理器。
1,安装php及php-fpm:
# yum -y install php php-fpm
设置php-fpm随系统启动:
# chkconfig php-fpm on
修改php-fpm配置文件:
# vim /etc/php-fpm.conf
error_log = /var/log/php-fpm/error.log
# vim /etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000
启动php-fpm:
# service php-fpm restart
Stopping php-fpm:                                          [  OK  ]
Starting php-fpm:                                          [  OK  ]

检查是否启动正确,监听9000端口:
# netstat -an | grep :9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN

# lsof -i:9000
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 3204   root    7u  IPv4  40935      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 3205 apache    0u  IPv4  40935      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 3206 apache    0u  IPv4  40935      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 3207 apache    0u  IPv4  40935      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 3208 apache    0u  IPv4  40935      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 3209 apache    0u  IPv4  40935      0t0  TCP localhost:cslistener (LISTEN)

安装php其它组件:
# yum -y install php-gd php-mysql php-mbstring php-xml php-mcrypt



2,安装配置nginx,并使php页面转交给php-fpm处理
安装nginx:
# yum -y install nginx
配置nginx:
# vim /etc/nginx/nginx.conf
# vim /etc/nginx/conf.d/default.conf
server {
        listen             8080;
        server_name    localhost;

        #charset koi8-r;
        access_log    /var/log/nginx/log/host.access.log    main;

        location / {
                #root     /usr/share/nginx/html;
                root     /var/www/html;
                index    index.html index.htm default.htm default.html index.php default.php;
        }

        #error_page    404                            /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page     500 502 503 504    /50x.html;
        location = /50x.html {
                root     /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #        proxy_pass     http://127.0.0.1:8080;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                root                     /var/www/html;
                fastcgi_pass     127.0.0.1:9000;
                fastcgi_index    index.php;
                fastcgi_param    SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                include                fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #        deny    all;
        #}
}




设置nginx随系统启动:
# chkconfig nginx on
重启nginx:
# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]

在网站目录 /var/www/html 下创建phpinfo.php:




关掉防火墙,访问http://192.168.1.18:8080/phpinfo.php,访问应该成功。


3, 安装squid
由于squid缓存文件将放在SSD盘里,因此需要将SSD随系统启动挂载。
首先找出SSD来:
# fdisk -l
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       14594   117218304    7  HPFS/NTFS

可知SSD盘符 /dev/sdc1, 且格式为NTFS;
首先格式化SSD为ext linux格式:
# mkfs.ext4 /dev/sdc1

将SSD挂载信息加入到/etc/fstab文件中
# vim /etc/fstab

/dev/sdc1                            /cache                 ext4    defaults,ssd,discard,noatime 2 1

并在当前挂载:
# mkdir /cache
# mount -o discard,noatime -t ext4 /dev/sdc1 /cache
再查看则可看到 /cache 目录:
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdc1             111G  188M  105G   1% /cache

创建squid需要的目录:
# mkdir -p /cache/spool/squid
关闭selinux,否则squid会报如下错误:
2012/09/30 09:05:46| /cache/spool/squid: (13) Permission denied
FATAL:    Failed to verify one of the swap directories, Check cache.log
                for details.    Run 'squid -z' to create swap directories
                if needed, or if running Squid for the first time.


解决这个问题:
# vim /etc/sysconfig/selinux
SELINUX=disabled
# setenforce 0


现在开始安装配置squid:
安装squid,运行下面命令,将会安装squid3.1:
# yum -y install squid
将squid设置随系统启动:
# chkconfig squid on
安装完后配置squid:
# vim /etc/squid/squid.conf
在文件末尾加上以下配置项,若前面有相同的注释掉原有的:
####### customazation #########
http_port 80 vhost
icp_port 0

cache_peer 192.168.1.18 parent 8080 0 no-query originserver weight=1 name=a
cache_peer_access a allow all

#cache_mem 0MB
memory_pools off
maximum_object_size 10 MB
maximum_object_size_in_memory 100 KB
negative_ttl 0 second
ipcache_size 10240
fqdncache_size 10240
#reply_body_max_size    1024000 allow all
cache_dir aufs /cache/spool/squid 10240 64 256
read_ahead_gap 20 KB

access_log /var/log/squid/access.log
#cache_access_log /var/squid/log/access.log
#logformat abc-squid %ts.%03tu %6tr %>a %Ss/%03Hs %

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-656769-1-1.html 上篇帖子: squid有些功能是默认没有开启的,需编译;不知后来有什么办法加进去,正在试验 下篇帖子: 初步试用Squid的替代产品──Varnish Cache网站加速器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表