隨筆-179  評(píng)論-666  文章-29  trackbacks-0
          阿里云服務(wù)器優(yōu)惠券
          1. 安裝 nginx 
            CentOS 7 沒(méi)有內(nèi)建的 nginx,所以先到 nginx 官網(wǎng)  http://nginx.org/en/linux_packages.html#stable ,找到 CentOS 7 的 nginx-release package 檔案連結(jié),然後如下安裝
            rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
            安裝後,會(huì)自動(dòng)產(chǎn)生 yum 的 repository 設(shè)定(在 /etc/yum.repos.d/nginx.repo), 
            接下來(lái)便可以使用 yum 指令安裝 nginx
            yum install nginx
          2. 啟動(dòng) nginx 
            以前用 chkconfig 管理服務(wù),CentOS 7 改用 systemctl 管理系統(tǒng)服務(wù) 
            立即啟動(dòng)
            systemctl start nginx
            查看目前運(yùn)作狀態(tài)
            systemctl status nginx
            查看 nginx 服務(wù)目前的啟動(dòng)設(shè)定
            systemctl list-unit-files | grep nginx
            若是 disabled,可以改成開(kāi)機(jī)自動(dòng)啟動(dòng)
            systemctl enable nginx
            若有設(shè)定防火牆,查看防火牆運(yùn)行狀態(tài),看是否有開(kāi)啟 nginx 使用的 port
            firewall-cmd --state
            永久開(kāi)放開(kāi)啟防火牆的 http 服務(wù)
            firewall-cmd --permanent --zone=public --add-service=http
            firewall-cmd --reload
            列出防火牆 public 的設(shè)定
            firewall-cmd --list-all --zone=public
            經(jīng)過(guò)以上設(shè)定,應(yīng)該就可以使用瀏覽器訪問(wèn) nginx 的預(yù)設(shè)頁(yè)面。
          3. 安裝 PHP-FPM 
            使用 yum 安裝 php、php-fpm、php-mysql
            yum install php php-fpm php-mysql
            查看 php-fpm 服務(wù)目前的啟動(dòng)設(shè)定 
            systemctl list-unit-files | grep php-fpm
            改成開(kāi)機(jī)自動(dòng)啟動(dòng)
            systemctl enable php-fpm
            立即啟動(dòng)
            systemctl start php-fpm
            查看目前運(yùn)作狀態(tài)
            systemctl status php-fpm
          4. 修改 PHP-FPM listen 的方式 
            若想將 PHP-FPM listen 的方式,改成 unix socket,可以編輯 /etc/php-fpm.d/www.conf 
            listen = 127.0.0.1:9000
            改成
            listen = /var/run/php-fpm/php-fpm.sock
            然後重新啟動(dòng) php-fpm
            systemctl restart php-fpm
            註:不要改成 listen = /tmp/php-fcgi.sock (將 php-fcgi.sock 設(shè)定在 /tmp 底下), 因?yàn)橄到y(tǒng)產(chǎn)生 php-fcgi.sock 時(shí),會(huì)放在 /tmp/systemd-private-*/tmp/php-fpm.sock 隨機(jī)私有目錄下, 除非把 /usr/lib/systemd/system/ 裡面的 PrivateTmp=true 設(shè)定改成 PrivateTmp=false, 但還是會(huì)產(chǎn)生其他問(wèn)題,所以還是換個(gè)位置最方便 


            刪除之前的版本

            # yum remove php*

            rpm 安裝 Php7 相應(yīng)的 yum源

            CentOS/RHEL 7.x:

            # rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

            CentOS/RHEL 6.x:
            # rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

            yum安裝php7

            yum install php70w php70w-opcache
            安裝其他插件(選裝)
            注:如果安裝pear,需要安裝php70w-devel
            php70w
            php70w-bcmath
            php70w-cli
            php70w-common
            php70w-dba
            php70w-devel
            php70w-embedded
            php70w-enchant
            php70w-fpm
            php70w-gd
            php70w-imap
            php70w-interbase
            php70w-intl
            php70w-ldap
            php70w-mbstring
            php70w-mcrypt
            php70w-mysql
            php70w-mysqlnd
            php70w-odbc
            php70w-opcache
            php70w-pdo
            php70w-pdo_dblib
            php70w-pear
            php70w-pecl-apcu
            php70w-pecl-imagick
            php70w-pecl-xdebug
            php70w-pgsql
            php70w-phpdbg
            php70w-process
            php70w-pspell
            php70w-recode
            php70w-snmp
            php70w-soap
            php70w-tidy
            php70w-xml
            php70w-xmlrp

            編譯安裝php7

            配置(configure)、編譯(make)、安裝(make install)

            使用configure --help

            編譯安裝一定要指定定prefix,這是安裝目錄,會(huì)把所有文件限制在這個(gè)目錄,卸載時(shí)只需要?jiǎng)h除那個(gè)目錄就可以,如果不指定會(huì)安裝到很多地方,后邊刪除不方便。

            Configuration: --cache-file=FILE cache test results in FILE --help print this message --no-create do not create output files --quiet, --silent do not print `checking...' messages --version print the version of autoconf that created configure Directory and file names: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX

            注意
            內(nèi)存小于1G安裝往往會(huì)出錯(cuò),在編譯參數(shù)后面加上一行內(nèi)容--disable-fileinfo

            其他配置參數(shù)

            --exec-prefix=EXEC-PREFIX
            可以把體系相關(guān)的文件安裝到一個(gè)不同的位置,而不是PREFIX設(shè)置的地方.這樣做可以比較方便地在不同主機(jī)之間共享體系相關(guān)的文件
            --bindir=DIRECTORY
            為可執(zhí)行程序聲明目錄,缺省是 EXEC-PREFIX/bin
            --datadir=DIRECTORY
            設(shè)置所安裝的程序需要的只讀文件的目錄.缺省是 PREFIX/share
            --sysconfdir=DIRECTORY
            用于各種各樣配置文件的目錄,缺省為 PREFIX/etc
            --libdir=DIRECTORY
            庫(kù)文件和動(dòng)態(tài)裝載模塊的目錄.缺省是 EXEC-PREFIX/lib
            --includedir=DIRECTORY
            C 和 C++ 頭文件的目錄.缺省是 PREFIX/include
            --docdir=DIRECTORY
            文檔文件,(除 “man(手冊(cè)頁(yè))”以外, 將被安裝到這個(gè)目錄.缺省是 PREFIX/doc
            --mandir=DIRECTORY
            隨著程序一起帶的手冊(cè)頁(yè) 將安裝到這個(gè)目錄.在它們相應(yīng)的manx子目錄里. 缺省是PREFIX/man
            注意: 為了減少對(duì)共享安裝位置(比如 /usr/local/include) 的污染,configure 自動(dòng)在 datadir, sysconfdir,includedir, 和 docdir 上附加一個(gè) “/postgresql” 字串, 除非完全展開(kāi)以后的目錄名字已經(jīng)包含字串 “postgres” 或者 “pgsql”.比如,如果你選擇 /usr/local 做前綴,那么 C 的頭文件將安裝到 /usr/local/include/postgresql, 但是如果前綴是 /opt/postgres,那么它們將 被放進(jìn) /opt/postgres/include
            --with-includes=DIRECTORIES
            DIRECTORIES 是一系列冒號(hào)分隔的目錄,這些目錄將被加入編譯器的頭文件 搜索列表中.如果你有一些可選的包(比如 GNU Readline)安裝在 非標(biāo)準(zhǔn)位置,你就必須使用這個(gè)選項(xiàng),以及可能還有相應(yīng)的 --with-libraries 選項(xiàng).
            --with-libraries=DIRECTORIES
            DIRECTORIES 是一系列冒號(hào)分隔的目錄,這些目錄是用于查找?guī)煳募模?如果你有一些包安裝在非標(biāo)準(zhǔn)位置,你可能就需要使用這個(gè)選項(xiàng) (以及對(duì)應(yīng)的--with-includes選項(xiàng))
            --enable-XXX
            打開(kāi)XXX支持
            --with-XXX
            制作XXX模塊

            • PHP FPM設(shè)定參考
              [global]
                       pid = /usr/local/php/var/run/php-fpm.pid
                       error_log = /usr/local/php/var/log/php-fpm.log
                       [www]
                       listen = /var/run/php-fpm/php-fpm.sock
                       user = www
                       group = www
                       pm = dynamic
                       pm.max_children = 800
                       pm.start_servers = 200
                       pm.min_spare_servers = 100
                       pm.max_spare_servers = 800
                       pm.max_requests = 4000
                       rlimit_files = 51200
                       listen.backlog = 65536
                       ;設(shè) 65536 的原因是-1 可能不是unlimited
                       ;說(shuō)明 http://php.net/manual/en/install.fpm.configuration.php#104172
                       slowlog = /usr/local/php/var/log/slow.log
                       request_slowlog_timeout = 10
            • nginx.conf 設(shè)定參考 
              user nginx;
                       worker_processes 8;
                       error_log /var/log/nginx/error.log warn;
                       pid /var/run/nginx.pid;
                       events {
                        use epoll;
                        worker_connections 65535;
                       }
                       worker_rlimit_nofile 65535;
                       #若沒(méi)設(shè)定,可能出現(xiàn)錯(cuò)誤:65535 worker_connections exceed open file resource limit: 1024
                       http {
                        include /etc/nginx/mime.types;
                        default_type application/octet-stream;
                        log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                             '$status $body_bytes_sent "$http_referer" '
                             '"$http_user_agent" "$http_x_forwarded_for"';
                        access_log /var/log/nginx/access.log main;
                        sendfile on;
                        tcp_nopush on;
                        keepalive_timeout 65;
                        server_names_hash_bucket_size 128;
                        client_header_buffer_size 32k;
                        large_client_header_buffers 4 32k;
                        client_max_body_size 8m;
                        server_tokens off;
                        client_body_buffer_size 512k;
                        # fastcgi
                        fastcgi_connect_timeout 300;
                        fastcgi_send_timeout 300;
                        fastcgi_read_timeout 300;
                        fastcgi_buffer_size 64k;
                        fastcgi_buffers 4 64k;
                        fastcgi_busy_buffers_size 128k;
                        fastcgi_temp_file_write_size 128k;
                        fastcgi_intercept_errors on;
                        #gzip (說(shuō)明 http://nginx.org/en/docs/http/ngx_http_gzip_module.html)
                        gzip off;
                        gzip_min_length 1k;#1k以上才壓縮
                        gzip_buffers 32 4k;
                         #http://stackoverflow.com/questions/4888067/how-to-get-linux-kernel-page-size-programatically
                         #使用 getconf PAGESIZE 取得系統(tǒng) one memory page size,
                        gzip_http_version 1.0;
                        gzip_comp_level 2;
                        gzip_types text/css text/xml application/javascript application/atom+xml application/rss+xml text/plain application/json;
                         #查看 nginx 的 mime.types 檔案(/etc/nginx/mime.types),裡面有各種類(lèi)型的定義
                        gzip_vary on;
                        include /etc/nginx/conf.d/*.conf;
                       }
                       
              若出現(xiàn)出現(xiàn)錯(cuò)誤:setrlimit(RLIMIT_NOFILE, 65535) failed (1: Operation not permitted) 
              先查看目前系統(tǒng)的設(shè)定值
              ulimit -n
              若設(shè)定值太小,修改 /etc/security/limits.conf
              vi /etc/security/limits.conf
              加上或修改以下兩行設(shè)定
              * soft nofile 65535
                       * hard nofile 65535



          阿里云服務(wù)器優(yōu)惠券
          posted on 2016-08-10 13:44 Alpha 閱讀(6041) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Linux Nginx
          主站蜘蛛池模板: 隆德县| 广宗县| 杭州市| 厦门市| 金山区| 商南县| 临泉县| 乡城县| 女性| 馆陶县| 郴州市| 梁河县| 靖州| 包头市| 连城县| 阜宁县| 肃宁县| 寿阳县| 封开县| 许昌市| 阳新县| 左云县| 额敏县| 泽库县| 长岛县| 安平县| 聂荣县| 涟源市| 锦州市| 神木县| 凌源市| 安康市| 多伦县| 汝南县| 会泽县| 临海市| 胶南市| 安顺市| 龙里县| 海原县| 曲松县|