首页 » 网站推广 » nginx110php技巧_nginx设备案例和技巧

nginx110php技巧_nginx设备案例和技巧

访客 2024-11-07 0

扫一扫用手机浏览

文章目录 [+]

一:nginx tcp

nginx 配置支持TCP

nginx110php技巧_nginx设备案例和技巧

1)版本 1.9.x 之后的版本

nginx110php技巧_nginx设备案例和技巧
(图片来自网络侵删)

2)nginx -V

检讨是否有 --with-stream=dynamic 或 --with-stream

3)查找是否有ngx_stream编译的so

locate ngx_stream_module.so

/usr/lib64/nginx/modules/ngx_stream_module.so

4)在nginx.conf中配置模块加载

[root@Q-gz-fat-pub-ms-webui /etc/nginx]$ more nginx.conf

load_module /usr/lib64/nginx/modules/ngx_stream_module.so;

5)stream 配置须要和http同属一个层级

即存放到nginx.conf主配置文件中,如果不在则非常

nginx -t

nginx: [emerg] "stream" directive is not allowed here in /etc/nginx/conf.d/dts-tcp.conf:1

nginx: configuration file /etc/nginx/nginx.conf test failed

6)配置参数

#dts tcp exchanger

stream {

upstream cloudsocket {

hash $remote_addr consistent;

# $binary_remote_addr;

server 10.2.80.76:8888 weight=5 max_fails=3 fail_timeout=30s;

}

server {

listen 8888;#数据库做事器监听端口

proxy_connect_timeout 10s;

proxy_timeout 300s;#设置客户端和代理做事之间的超时时间,如果5分钟内没操作将自动断开。

proxy_pass cloudsocket;

}

}

7)测试配置文件是否OK

nginx -t

nginx: [warn] conflicting server name "129.204.233.124" on 0.0.0.0:80, ignored

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

二:nginx 日志切割

展开

logrotate linux 命令 在线中文手册

logrotate,linux 命令 例子

设置nignx 日志切割 root@Q-gz-templerun2-WEB-1:/var/spool/cron/crontabs# cat /etc/logrotate.d/nginx

/data/log/nginx/.log { daily minsize 100M missingok rotate 5 compress delaycompress notifempty sharedscripts postrotate /data/app/nginx/sbin/nginx -s reload endscript}

手动实行: logrotate -f /etc/logrotate.d/nginx

三:centos nginx php7

centos 7.6 nginx1.16 php7

nginx 安装

yum install gcc-c++

yum install -y openssl openssl-devel

yum install -y pcre pcre-devel

yum install -y zlib zlib-devel

wget http://nginx.org/download/nginx-1.16.0.tar.gz

解压压缩包

tar -zxvf nginx-1.16.0.tar.gz

切换到相应目录

cd nginx-1.16.0

编译安装

./configure

make && make install

不修正配置的话默认安装在 /usr/local/nginx 文件中 ,安装完成后可以删除安装包了,压缩包一样平常都保留,如果你以为这点小文件会影响你得硬盘容量的话也可以删除掉

启动

cd /usr/local/nginx/sbin

./nginx

正常来说到这一步就已经算启动成功了

可以实行 ps -ef | grep nginx 看一下进程有没有跑起来

如下图所示就已经算安装并运行成功了

然后把nginx命令加入环境变量,方便我们之后命令行操作

vim /etc/profile

修正环境变量文件,里边东西不用管直接GG拉到文档最下方,添加

export PATH=$PATH:/usr/local/nginx/sbin

(这里指出一点 有些人会单独把“/usr./local/nginx”单独抽出来,为了之后改nginx安装目录好修正。
大略点理解可以理解为程序的封装。
这里就大略一写)然后保存,退出,重新初始化一下资源才会生效

source /etc/profile

至此,nginx安装以及配置就算完成了。

安装php7.1

wget https://www.php.net/distributions/php-7.1.33.tar.gz

tar zxvf php-7.1.33.tar.gz

yum -y install libxml2-devel

yum -y install bzip2

yum -y install bzip2-devel.x86_64

yum -y install curl-devel

yum -y install enchant-devel

yum -y install libwebp libwebp-devel

yum -y install libjpeg-devel

yum -y install libpng

yum -y install libpng-devel

yum -y install libXpm-devel

yum -y install freetype-devel

yum -y install gmp-devel

yum -y install libc-client-devel

ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so (做软链,为了能安装时能读到文件)

yum -y install openldap-devel

cp -frp /usr/lib64/libldap /usr/lib/(移动安装目录)

yum -y install epel-release

yum -y install libmcrypt-devel

yum -y install pspell-devel

yum -y install libtidy-devel

yum -y install libxslt libxslt-devel

yum -y install readline

yum -y install readline-devel

yum -y install autoconf

编译

./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--with-config-file-scan-dir=/usr/local/php/lib/php.d \

--with-mcrypt=/usr/include \

--with-sqlite3 \

--with-pdo-sqlite \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--enable-posix \

--enable-pcntl \

--enable-shmop \

--enable-sysvshm \

--enable-sysvsem \

--enable-sysvmsg \

--enable-phar \

--enable-zip \

--with-zlib \

--with-zlib-dir \

--with-bz2 \

--with-gd \

--enable-gd-native-ttf \

--enable-gd-jis-conv \

--with-webp-dir \

--with-jpeg-dir \

--with-png-dir \

--with-xpm-dir \

--with-freetype-dir \

--enable-exif \

--enable-json \

--enable-libxml \

--with-libxml-dir \

--enable-xml \

--enable-xmlreader \

--enable-xmlwriter \

--enable-simplexml \

--with-pear \

--with-xsl \

--enable-dom \

--enable-soap \

--enable-wddx \

--with-xmlrpc \

--enable-ctype \

--enable-filter \

--with-pcre-regex \

--with-pcre-jit \

--with-enchant \

--enable-fileinfo \

--enable-mbstring \

--with-iconv \

--enable-hash \

--with-openssl \

--with-mcrypt \

--enable-bcmath \

--with-gmp \

--enable-session \

--enable-sockets \

--enable-ftp \

--with-curl \

--with-ldap \

--with-ldap-sasl \

--with-imap \

--with-kerberos \

--with-imap-ssl \

--enable-calendar \

--with-gettext \

--with-tidy \

--with-readline \

--enable-tokenizer \

--enable-opcache \

--enable-cli \

--enable-cgi \

--enable-fpm \

--enable-phpdbg\

然后

make && make install

然后安装完成,我们去配置php

cp php.ini-production /usr/local/php/etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

/etc/profile

#nginx

export PATH=$PATH:/usr/local/nginx/sbin

export PATH=$PATH:/usr/local/php/sbin

export PATH=$PATH:/usr/local/php/bin

编译缺点:

php 编译缺点 /lib64/liblber-2.4.so.2: could not read symbols: Invalid operation

./configure后

编辑MakeFile

找到 开头是 'EXTRA_LIBS' 这一行 在结尾加上 '-llber' 然后实行 make && make install

安装php-redis扩展

1、 下载redis扩展

root@~#wget http://pecl.php.net/get/redis-4.2.0.tgz

root@~#tar zxf redis-4.2.0.tgz

2、 编译安装

root@~#cd redis-4.2.0 //进入安装目录

root@~#/usr/bin/phpize

#//不知道路径的话,可以用whereis phpize命令查找

root@~#./configure --with-php-config=/usr/local/php/bin/php-config

# //不知道路径的话,可以用 find / -name php-config查找

root@~#make && make install

3、 编辑php.ini文件

root@~#vim /usr/local/php/etc/php.ini #这个是php的安装路径下的php.ini

extension=redis.so #加上这个扩展

4、查看是否安装成功

root@~#php -m | grep redis

redis #如果有则表示安装redis-php扩展成功

安装kafka对php的支持

1、安装librdkafka

root@~# git clone https://github.com/edenhill/librdkafka.git

root@~# cd librdkafka

root@~# ./configure

root@~# make

root@~# make install

root@~# ln -s /usr/local/lib/librdkafka.so.1 /usr/lib/

安装php-rdkafka

root@~# cd /usr/local/src/

root@~# git clone https://github.com/arnaud-lb/php-rdkafka.git

root@~# cd php-rdkafka

root@~# /usr/local/php/bin/phpize

root@~# ./configure --with-php-config=/usr/local/php/bin/php-config

root@~# make all -j 5

root@~# make install

添加扩展,重启php

root@~# vim /usr/local/php/etc/php.ini

extension=rdkafka.so

root@~#php -m | grep rdkafka

rdkafka #如果有则表示安装rdkafka扩展成功

标签:

相关文章

php常量率低技巧_PHP 常量详解教程

PHP 常量常量是单个值的标识符(名称)。在脚本中无法改变该值。有效的常量名以字符或下划线开头(常量名称前面没有 $ 符号)。注释...

网站推广 2024-12-19 阅读0 评论0