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

[经验分享] CentOS Nginx PHP MySQL Memcached 安装 配置 优化 (二)

[复制链接]

尚未签到

发表于 2016-5-12 10:19:09 | 显示全部楼层 |阅读模式
  接上篇  CentOS Nginx PHP MySQL Memcached 安装 配置 优化

四、配置篇
4.1 mysql配置

  • mkdir -p /var/mysql/
  • mkdir -p /var/mysql/data/
  • mkdir -p /var/mysql/log/
  • chown -R mysql:mysql /var/mysql/
  • /usr/local/mysql/bin/mysql_install_db \
  • --defaults-file=/var/mysql/my.cnf \
  • --basedir=/usr/local/mysql \
  • --datadir=/var/mysql/data \
  • --user=mysql
  • vi /var/mysql/my.cnf

复制代码
  请复制以下内容至 my.cnf 文件:


  • [client]
  • #character-set-server = utf8
  • port = 3306
  • socket = /tmp/mysql.sock
  • [mysqld]
  • character-set-server = utf8
  • replicate-ignore-db = mysql
  • replicate-ignore-db = test
  • replicate-ignore-db = information_schema
  • user = mysql
  • port = 3306
  • socket = /tmp/mysql.sock
  • basedir = /usr/local/mysql
  • datadir = /var/mysql/data
  • log-error = /var/mysql/log/error.log
  • pid-file = /var/mysql/mysql.pid
  • open_files_limit = 10240
  • back_log = 600
  • max_connections = 5000
  • max_connect_errors = 6000
  • table_cache = 614
  • external-locking = FALSE
  • max_allowed_packet = 32M
  • sort_buffer_size = 1M
  • join_buffer_size = 1M
  • thread_cache_size = 300
  • #thread_concurrency = 8
  • query_cache_size = 512M
  • query_cache_limit = 2M
  • query_cache_min_res_unit = 2k
  • default-storage-engine = MyISAM
  • thread_stack = 192K
  • transaction_isolation = READ-COMMITTED
  • tmp_table_size = 246M
  • max_heap_table_size = 246M
  • long_query_time = 3
  • log-slave-updates
  • log-bin = /var/mysql/log/binlog
  • binlog_cache_size = 4M
  • binlog_format = MIXED
  • max_binlog_cache_size = 8M
  • max_binlog_size = 1G
  • relay-log-index = /var/mysql/log/relaylog
  • relay-log-info-file = /var/mysql/log/relaylog
  • relay-log = /var/mysql/log/relaylog
  • expire_logs_days = 30
  • key_buffer_size = 256M
  • read_buffer_size = 1M
  • read_rnd_buffer_size = 16M
  • bulk_insert_buffer_size = 64M
  • myisam_sort_buffer_size = 128M
  • myisam_max_sort_file_size = 10G
  • myisam_repair_threads = 1
  • myisam_recover
  • interactive_timeout = 120
  • wait_timeout = 120
  • skip-name-resolve
  • #master-connect-retry = 10
  • slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
  • #master-host = 192.168.1.2
  • #master-user = username
  • #master-password = password
  • #master-port = 3306

  • server-id = 1
  • innodb_additional_mem_pool_size = 16M
  • innodb_buffer_pool_size = 512M
  • innodb_data_file_path = ibdata1:256M:autoextend
  • innodb_file_io_threads = 4
  • innodb_thread_concurrency = 8
  • innodb_flush_log_at_trx_commit = 2
  • innodb_log_buffer_size = 16M
  • innodb_log_file_size = 128M
  • innodb_log_files_in_group = 3
  • innodb_max_dirty_pages_pct = 90
  • innodb_lock_wait_timeout = 120
  • innodb_file_per_table = 0
  • #log-slow-queries = /var/mysql/log/slow.log
  • #long_query_time = 10
  • [mysqldump] quick max_allowed_packet = 32M

复制代码
  4.2 PHP配置

  • vi /usr/local/php/etc/php.ini

复制代码
  查找 extension_dir = "ext"(809行左右),在后面添加以下几行:

  • extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
  • extension=apc.so
  • extension=imagick.so
  • extension=memcache.so

复制代码
  按shift+g键跳到配置文件的末尾,添加以下配置信息:

  • [APC]
  • apc.enabled=1
  • apc.ttl=7200
  • apc.shm_size=32

复制代码
  4.3 PHP-FPM配置

  • cd /usr/local/php/etc/
  • cp php-fpm.conf.default php-fpm.conf
  • vi php-fpm.conf

复制代码
  请根据以下内容修改文件 php-fpm.conf 的具体内容:


  • ;;;;;;;;;;;;;;;;;;;;;
  • ; FPM Configuration ;
  • ;;;;;;;;;;;;;;;;;;;;;

  • ; All relative paths in this configuration file are relative to PHP's install
  • ; prefix (/usr/local/web/php). This prefix can be dynamicaly changed by using the
  • ; '-p' argument from the command line.

  • ; Include one or more files. If glob(3) exists, it is used to include a bunch of
  • ; files from a glob(3) pattern. This directive can be used everywhere in the
  • ; file.
  • ; Relative path can also be used. They will be prefixed by:
  • ;  - the global prefix if it's been set (-p arguement)
  • ;  - /usr/local/web/php otherwise
  • ;include=etc/fpm.d/*.conf

  • ;;;;;;;;;;;;;;;;;;
  • ; Global Options ;
  • ;;;;;;;;;;;;;;;;;;

  • [global]
  • ; Pid file
  • ; Note: the default prefix is /usr/local/web/php/var
  • ; Default Value: none
  • ;pid = run/php-fpm.pid
  • pid = /var/run/php-fpm.pid

  • ; Error log file
  • ; If it's set to "syslog", log is sent to syslogd instead of being written
  • ; in a local file.
  • ; Note: the default prefix is /usr/local/web/php/var
  • ; Default Value: log/php-fpm.log
  • ;error_log = log/php-fpm.log
  • error_log = /var/log/php-fpm.log

  • ; syslog_facility is used to specify what type of program is logging the
  • ; message. This lets syslogd specify that messages from different facilities
  • ; will be handled differently.
  • ; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
  • ; Default Value: daemon
  • ;syslog.facility = daemon

  • ; syslog_ident is prepended to every message. If you have multiple FPM
  • ; instances running on the same server, you can change the default value
  • ; which must suit common needs.
  • ; Default Value: php-fpm
  • ;syslog.ident = php-fpm

  • ; Log level
  • ; Possible Values: alert, error, warning, notice, debug
  • ; Default Value: notice
  • ;log_level = notice

  • ; If this number of child processes exit with SIGSEGV or SIGBUS within the time
  • ; interval set by emergency_restart_interval then FPM will restart. A value
  • ; of '0' means 'Off'.
  • ; Default Value: 0
  • ;emergency_restart_threshold = 0
  • emergency_restart_threshold = 10

  • ; Interval of time used by emergency_restart_interval to determine when
  • ; a graceful restart will be initiated.  This can be useful to work around
  • ; accidental corruptions in an accelerator's shared memory.
  • ; Available Units: s(econds), m(inutes), h(ours), or d(ays)
  • ; Default Unit: seconds
  • ; Default Value: 0
  • ;emergency_restart_interval = 0
  • emergency_restart_interval = 1m

  • ; Time limit for child processes to wait for a reaction on signals from master.
  • ; Available units: s(econds), m(inutes), h(ours), or d(ays)
  • ; Default Unit: seconds
  • ; Default Value: 0
  • ;process_control_timeout = 0
  • process_control_timeout = 5m

  • ; The maximum number of processes FPM will fork. This has been design to control
  • ; the global number of processes when using dynamic PM within a lot of pools.
  • ; Use it with caution.
  • ; Note: A value of 0 indicates no limit
  • ; Default Value: 0
  • ; process.max = 128

  • ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
  • ; Default Value: yes
  • ;daemonize = yes
  • daemonize = yes

  • ; Set open file descriptor rlimit for the master process.
  • ; Default Value: system defined value
  • ;rlimit_files = 1024
  • rlimit_files = 65535

  • ; Set max core size rlimit for the master process.
  • ; Possible Values: 'unlimited' or an integer greater or equal to 0
  • ; Default Value: system defined value
  • ;rlimit_core = 0
  • rlimit_core = 0

  • ; Specify the event mechanism FPM will use. The following is available:
  • ; - select     (any POSIX os)
  • ; - poll       (any POSIX os)
  • ; - epoll      (linux >= 2.5.44)
  • ; - kqueue     (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
  • ; - /dev/poll  (Solaris >= 7)
  • ; - port       (Solaris >= 10)
  • ; Default Value: not set (auto detection)
  • ; events.mechanism = epoll

  • ;;;;;;;;;;;;;;;;;;;;
  • ; Pool Definitions ;
  • ;;;;;;;;;;;;;;;;;;;;

  • ; Multiple pools of child processes may be started with different listening
  • ; ports and different management options.  The name of the pool will be
  • ; used in logs and stats. There is no limitation on the number of pools which
  • ; FPM can handle. Your system will tell you anyway :)

  • ; Start a new pool named 'www'.
  • ; the variable $pool can we used in any directive and will be replaced by the
  • ; pool name ('www' here)
  • [www]

  • ; Per pool prefix
  • ; It only applies on the following directives:
  • ; - 'slowlog'
  • ; - 'listen' (unixsocket)
  • ; - 'chroot'
  • ; - 'chdir'
  • ; - 'php_values'
  • ; - 'php_admin_values'
  • ; When not set, the global prefix (or /usr/local/web/php) applies instead.
  • ; Note: This directive can also be relative to the global prefix.
  • ; Default Value: none
  • ;prefix = /path/to/pools/$pool

  • ; Unix user/group of processes
  • ; Note: The user is mandatory. If the group is not set, the default user's group
  • ;       will be used.
  • user = www
  • group = www
  • ;user = nobody
  • ;group = nobody

  • ; The address on which to accept FastCGI requests.
  • ; Valid syntaxes are:
  • ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
  • ;                            a specific port;
  • ;   'port'                 - to listen on a TCP socket to all addresses on a
  • ;                            specific port;
  • ;   '/path/to/unix/socket' - to listen on a unix socket.
  • ; Note: This value is mandatory.
  • listen = 127.0.0.1:9000

  • ; Set listen(2) backlog.
  • ; Default Value: 128 (-1 on FreeBSD and OpenBSD)
  • ;listen.backlog = 128

  • ; Set permissions for unix socket, if one is used. In Linux, read/write
  • ; permissions must be set in order to allow connections from a web server. Many
  • ; BSD-derived systems allow connections regardless of permissions.
  • ; Default Values: user and group are set as the running user
  • ;                 mode is set to 0666
  • ;listen.owner = nobody
  • ;listen.group = nobody
  • ;listen.mode = 0666

  • ; List of ipv4 addresses of FastCGI clients which are allowed to connect.
  • ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
  • ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
  • ; must be separated by a comma. If this value is left blank, connections will be
  • ; accepted from any ip address.
  • ; Default Value: any
  • ;listen.allowed_clients = 127.0.0.1

  • ; Choose how the process manager will control the number of child processes.
  • ; Possible Values:
  • ;   static  - a fixed number (pm.max_children) of child processes;
  • ;   dynamic - the number of child processes are set dynamically based on the
  • ;             following directives. With this process management, there will be
  • ;             always at least 1 children.
  • ;             pm.max_children      - the maximum number of children that can
  • ;                                    be alive at the same time.
  • ;             pm.start_servers     - the number of children created on startup.
  • ;             pm.min_spare_servers - the minimum number of children in 'idle'
  • ;                                    state (waiting to process). If the number
  • ;                                    of 'idle' processes is less than this
  • ;                                    number then some children will be created.
  • ;             pm.max_spare_servers - the maximum number of children in 'idle'
  • ;                                    state (waiting to process). If the number
  • ;                                    of 'idle' processes is greater than this
  • ;                                    number then some children will be killed.
  • ;  ondemand - no children are created at startup. Children will be forked when
  • ;             new requests will connect. The following parameter are used:
  • ;             pm.max_children           - the maximum number of children that
  • ;                                         can be alive at the same time.
  • ;             pm.process_idle_timeout   - The number of seconds after which
  • ;                                         an idle process will be killed.
  • ; Note: This value is mandatory.
  • pm = dynamic

  • ; The number of child processes to be created when pm is set to 'static' and the
  • ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
  • ; This value sets the limit on the number of simultaneous requests that will be
  • ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
  • ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
  • ; CGI. The below defaults are based on a server without much resources. Don't
  • ; forget to tweak pm.* to fit your needs.
  • ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
  • ; Note: This value is mandatory.
  • pm.max_children = 128

  • ; The number of child processes created on startup.
  • ; Note: Used only when pm is set to 'dynamic'
  • ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
  • pm.start_servers = 8

  • ; The desired minimum number of idle server processes.
  • ; Note: Used only when pm is set to 'dynamic'
  • ; Note: Mandatory when pm is set to 'dynamic'
  • pm.min_spare_servers = 8

  • ; The desired maximum number of idle server processes.
  • ; Note: Used only when pm is set to 'dynamic'
  • ; Note: Mandatory when pm is set to 'dynamic'
  • pm.max_spare_servers = 64

  • ; The number of seconds after which an idle process will be killed.
  • ; Note: Used only when pm is set to 'ondemand'
  • ; Default Value: 10s
  • ;pm.process_idle_timeout = 10s;

  • ; The number of requests each child process should execute before respawning.
  • ; This can be useful to work around memory leaks in 3rd party libraries. For
  • ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
  • ; Default Value: 0
  • ;pm.max_requests = 500
  • pm.max_requests = 1024

  • ; The URI to view the FPM status page. If this value is not set, no URI will be
  • ; recognized as a status page. It shows the following informations:
  • ;   pool                 - the name of the pool;
  • ;   process manager      - static, dynamic or ondemand;
  • ;   start time           - the date and time FPM has started;
  • ;   start since          - number of seconds since FPM has started;
  • ;   accepted conn        - the number of request accepted by the pool;
  • ;   listen queue         - the number of request in the queue of pending
  • ;                          connections (see backlog in listen(2));
  • ;   max listen queue     - the maximum number of requests in the queue
  • ;                          of pending connections since FPM has started;
  • ;   listen queue len     - the size of the socket queue of pending connections;
  • ;   idle processes       - the number of idle processes;
  • ;   active processes     - the number of active processes;
  • ;   total processes      - the number of idle + active processes;
  • ;   max active processes - the maximum number of active processes since FPM
  • ;                          has started;
  • ;   max children reached - number of times, the process limit has been reached,
  • ;                          when pm tries to start more children (works only for
  • ;                          pm 'dynamic' and 'ondemand');
  • ; Value are updated in real time.
  • ; Example output:
  • ;   pool:                 www
  • ;   process manager:      static
  • ;   start time:           01/Jul/2011:17:53:49 +0200
  • ;   start since:          62636
  • ;   accepted conn:        190460
  • ;   listen queue:         0
  • ;   max listen queue:     1
  • ;   listen queue len:     42
  • ;   idle processes:       4
  • ;   active processes:     11
  • ;   total processes:      15
  • ;   max active processes: 12
  • ;   max children reached: 0
  • ;
  • ; By default the status page output is formatted as text/plain. Passing either
  • ; 'html', 'xml' or 'json' in the query string will return the corresponding
  • ; output syntax. Example:
  • ;   http://www.foo.bar/status
  • ;   http://www.foo.bar/status?json
  • ;   http://www.foo.bar/status?html
  • ;   http://www.foo.bar/status?xml
  • ;
  • ; By default the status page only outputs short status. Passing 'full' in the
  • ; query string will also return status for each pool process.
  • ; Example:
  • ;   http://www.foo.bar/status?full
  • ;   http://www.foo.bar/status?json&full
  • ;   http://www.foo.bar/status?html&full
  • ;   http://www.foo.bar/status?xml&full
  • ; The Full status returns for each process:
  • ;   pid                  - the PID of the process;
  • ;   state                - the state of the process (Idle, Running, ...);
  • ;   start time           - the date and time the process has started;
  • ;   start since          - the number of seconds since the process has started;
  • ;   requests             - the number of requests the process has served;
  • ;   request duration     - the duration in μs of the requests;
  • ;   request method       - the request method (GET, POST, ...);
  • ;   request URI          - the request URI with the query string;
  • ;   content length       - the content length of the request (only with POST);
  • ;   user                 - the user (PHP_AUTH_USER) (or '-' if not set);
  • ;   script               - the main script called (or '-' if not set);
  • ;   last request cpu     - the %cpu the last request consumed
  • ;                          it's always 0 if the process is not in Idle state
  • ;                          because CPU calculation is done when the request
  • ;                          processing has terminated;
  • ;   last request memory  - the max amount of memory the last request consumed
  • ;                          it's always 0 if the process is not in Idle state
  • ;                          because memory calculation is done when the request
  • ;                          processing has terminated;
  • ; If the process is in Idle state, then informations are related to the
  • ; last request the process has served. Otherwise informations are related to
  • ; the current request being served.
  • ; Example output:
  • ;   ************************
  • ;   pid:                  31330
  • ;   state:                Running
  • ;   start time:           01/Jul/2011:17:53:49 +0200
  • ;   start since:          63087
  • ;   requests:             12808
  • ;   request duration:     1250261
  • ;   request method:       GET
  • ;   request URI:          /test_mem.php?N=10000
  • ;   content length:       0
  • ;   user:                 -
  • ;   script:               /home/fat/web/docs/php/test_mem.php
  • ;   last request cpu:     0.00
  • ;   last request memory:  0
  • ;
  • ; Note: There is a real-time FPM status monitoring sample web page available
  • ;       It's available in: ${prefix}/share/fpm/status.html
  • ;
  • ; Note: The value must start with a leading slash (/). The value can be
  • ;       anything, but it may not be a good idea to use the .php extension or it
  • ;       may conflict with a real PHP file.
  • ; Default Value: not set
  • pm.status_path = /status

  • ; The ping URI to call the monitoring page of FPM. If this value is not set, no
  • ; URI will be recognized as a ping page. This could be used to test from outside
  • ; that FPM is alive and responding, or to
  • ; - create a graph of FPM availability (rrd or such);
  • ; - remove a server from a group if it is not responding (load balancing);
  • ; - trigger alerts for the operating team (24/7).
  • ; Note: The value must start with a leading slash (/). The value can be
  • ;       anything, but it may not be a good idea to use the .php extension or it
  • ;       may conflict with a real PHP file.
  • ; Default Value: not set
  • ;ping.path = /ping

  • ; This directive may be used to customize the response of a ping request. The
  • ; response is formatted as text/plain with a 200 response code.
  • ; Default Value: pong
  • ;ping.response = pong

  • ; The access log file
  • ; Default: not set
  • ;access.log = log/$pool.access.log

  • ; The access log format.
  • ; The following syntax is allowed
  • ;  %%: the '%' character
  • ;  %C: %CPU used by the request
  • ;      it can accept the following format:
  • ;      - %{user}C for user CPU only
  • ;      - %{system}C for system CPU only
  • ;      - %{total}C  for user + system CPU (default)
  • ;  %d: time taken to serve the request
  • ;      it can accept the following format:
  • ;      - %{seconds}d (default)
  • ;      - %{miliseconds}d
  • ;      - %{mili}d
  • ;      - %{microseconds}d
  • ;      - %{micro}d
  • ;  %e: an environment variable (same as $_ENV or $_SERVER)
  • ;      it must be associated with embraces to specify the name of the env
  • ;      variable. Some exemples:
  • ;      - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
  • ;      - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
  • ;  %f: script filename
  • ;  %l: content-length of the request (for POST request only)
  • ;  %m: request method
  • ;  %M: peak of memory allocated by PHP
  • ;      it can accept the following format:
  • ;      - %{bytes}M (default)
  • ;      - %{kilobytes}M
  • ;      - %{kilo}M
  • ;      - %{megabytes}M
  • ;      - %{mega}M
  • ;  %n: pool name
  • ;  %o: ouput header
  • ;      it must be associated with embraces to specify the name of the header:
  • ;      - %{Content-Type}o
  • ;      - %{X-Powered-By}o
  • ;      - %{Transfert-Encoding}o
  • ;      - ....
  • ;  %p: PID of the child that serviced the request
  • ;  %P: PID of the parent of the child that serviced the request
  • ;  %q: the query string
  • ;  %Q: the '?' character if query string exists
  • ;  %r: the request URI (without the query string, see %q and %Q)
  • ;  %R: remote IP address
  • ;  %s: status (response code)
  • ;  %t: server time the request was received
  • ;      it can accept a strftime(3) format:
  • ;      %d/%b/%Y:%H:%M:%S %z (default)
  • ;  %T: time the log has been written (the request has finished)
  • ;      it can accept a strftime(3) format:
  • ;      %d/%b/%Y:%H:%M:%S %z (default)
  • ;  %u: remote user
  • ;
  • ; Default: "%R - %u %t \"%m %r\" %s"
  • ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"

  • ; The log file for slow requests
  • ; Default Value: not set
  • ; Note: slowlog is mandatory if request_slowlog_timeout is set
  • ;slowlog = log/$pool.log.slow
  • slowlog = /var/log/php-fpm.log.slow

  • ; The timeout for serving a single request after which a PHP backtrace will be
  • ; dumped to the 'slowlog' file. A value of '0s' means 'off'.
  • ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
  • ; Default Value: 0
  • ;request_slowlog_timeout = 0
  • request_slowlog_timeout = 30s

  • ; The timeout for serving a single request after which the worker process will
  • ; be killed. This option should be used when the 'max_execution_time' ini option
  • ; does not stop script execution for some reason. A value of '0' means 'off'.
  • ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
  • ; Default Value: 0
  • ;request_terminate_timeout = 0

  • ; Set open file descriptor rlimit.
  • ; Default Value: system defined value
  • ;rlimit_files = 1024

  • ; Set max core size rlimit.
  • ; Possible Values: 'unlimited' or an integer greater or equal to 0
  • ; Default Value: system defined value
  • ;rlimit_core = 0

  • ; Chroot to this directory at the start. This value must be defined as an
  • ; absolute path. When this value is not set, chroot is not used.
  • ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
  • ; of its subdirectories. If the pool prefix is not set, the global prefix
  • ; will be used instead.
  • ; Note: chrooting is a great security feature and should be used whenever
  • ;       possible. However, all PHP paths will be relative to the chroot
  • ;       (error_log, sessions.save_path, ...).
  • ; Default Value: not set
  • ;chroot =

  • ; Chdir to this directory at the start.
  • ; Note: relative path can be used.
  • ; Default Value: current directory or / when chroot
  • ;chdir = /var/www
  • chdir = /var/www

  • ; Redirect worker stdout and stderr into main error log. If not set, stdout and
  • ; stderr will be redirected to /dev/null according to FastCGI specs.
  • ; Note: on highloaded environement, this can cause some delay in the page
  • ; process time (several ms).
  • ; Default Value: no
  • ;catch_workers_output = yes

  • ; Limits the extensions of the main script FPM will allow to parse. This can
  • ; prevent configuration mistakes on the web server side. You should only limit
  • ; FPM to .php extensions to prevent malicious users to use other extensions to
  • ; exectute php code.
  • ; Note: set an empty value to allow all extensions.
  • ; Default Value: .php
  • ;security.limit_extensions = .php .php3 .php4 .php5

  • ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
  • ; the current environment.
  • ; Default Value: clean env
  • ;env[HOSTNAME] = $HOSTNAME
  • ;env[PATH] = /usr/local/bin:/usr/bin:/bin
  • ;env[TMP] = /tmp
  • ;env[TMPDIR] = /tmp
  • ;env[TEMP] = /tmp

  • ; Additional php.ini defines, specific to this pool of workers. These settings
  • ; overwrite the values previously defined in the php.ini. The directives are the
  • ; same as the PHP SAPI:
  • ;   php_value/php_flag             - you can set classic ini defines which can
  • ;                                    be overwritten from PHP call 'ini_set'.
  • ;   php_admin_value/php_admin_flag - these directives won't be overwritten by
  • ;                                     PHP call 'ini_set'
  • ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.

  • ; Defining 'extension' will load the corresponding shared extension from
  • ; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
  • ; overwrite previously defined php.ini values, but will append the new value
  • ; instead.

  • ; Note: path INI options can be relative and will be expanded with the prefix
  • ; (pool, global or /usr/local/web/php)

  • ; Default Value: nothing is defined by default except the values in php.ini and
  • ;                specified at startup with the -d argument
  • ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
  • ;php_flag[display_errors] = off
  • ;php_admin_value[error_log] = /var/log/fpm-php.www.log
  • ;php_admin_flag[log_errors] = on
  • ;php_admin_value[memory_limit] = 32M

复制代码
  4.3Nginx配置


  • cd /usr/local/nginx/conf/
  • cp nginx.conf.default nginx.conf
  • vi nginx.conf

复制代码
  请根据以下内容修改文件 nginx.conf 的具体内容:




  • #user  nobody;
  • user  www www;
  • worker_processes  4;

  • error_log  /var/log/nginx_error.log crit;
  • #error_log  logs/error.log  notice;
  • #error_log  logs/error.log  info;

  • #pid        logs/nginx.pid;
  • pid        /var/run/nginx.pid;


  • events {
  •     worker_connections  65535;
  • }


  • http {
  •     include       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  logs/access.log  main;
  •     charset utf-8;
  •     server_names_hash_bucket_size 128;
  •     client_header_buffer_size 32k;
  •     large_client_header_buffers 4 32k;
  •     client_max_body_size 8m;
  •     sendfile on;
  •     tcp_nopush on;

  •     #tcp_nopush     on;

  •     #keepalive_timeout  0;
  •     keepalive_timeout  65;

  •     tcp_nodelay on;
  •     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;
  •     #gzip  on;
  •     gzip on;
  •     gzip_min_length 1k;
  •     gzip_buffers 4 16k;
  •     gzip_http_version 1.0;
  •     gzip_comp_level 2;
  •     gzip_types text/plain application/x-javascript text/css application/xml;
  •     gzip_vary on;

  •     server {
  •         listen       80;
  •         server_name  localhost;

  •         index index.html index.htm index.php;
  •         root /var/www;
  •         #charset koi8-r;

  •         #access_log  logs/host.access.log  main;

  •         location ~ .*\.(php|php5)?$ {
  •                 fastcgi_pass 127.0.0.1:9000;
  •                 fastcgi_index index.php;
  •                 include fastcgi.conf;
  •         }

  •         #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   html;
  •         }

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

  •         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  •         #
  •         #location ~ \.php$ {
  •         #    root           html;
  •         #    fastcgi_pass   127.0.0.1:9000;
  •         #    fastcgi_index  index.php;
  •         #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
  •         #}
  •         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/access.log  main;
  •     }


  •     # another virtual host using mix of IP-, name-, and port-based configuration
  •     #
  •     #server {
  •     #    listen       8000;
  •     #    listen       somename:8080;
  •     #    server_name  somename  alias  another.alias;

  •     #    location / {
  •     #        root   html;
  •     #        index  index.html index.htm;
  •     #    }
  •     #}


  •     # HTTPS server
  •     #
  •     #server {
  •     #    listen       443;
  •     #    server_name  localhost;

  •     #    ssl                  on;
  •     #    ssl_certificate      cert.pem;
  •     #    ssl_certificate_key  cert.key;

  •     #    ssl_session_timeout  5m;

  •     #    ssl_protocols  SSLv2 SSLv3 TLSv1;
  •     #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  •     #    ssl_prefer_server_ciphers   on;

  •     #    location / {
  •     #        root   html;
  •     #        index  index.html index.htm;
  •     #    }
  •     #}

  • }

复制代码
  五、启动篇
启动MySQL


  • cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/
  • chkconfig --add mysql.server ←加入service和开机启动
  • /etc/rc.d/init.d/mysql.server start ←手动启动,下面设置root密码
  • /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  • /usr/local/mysql/bin/mysqladmin -uroot -p shutdown ←手动关闭

复制代码
  启动memcached


  • chmod 0777 /var/run ←允许普通用户程序写入pid文件
  • /usr/local/memcached/bin/memcached -p 11211 -d -u www -P /var/run/memcached.pid -m 64M -c 1024

复制代码
  参考命令格式:
/usr/local/memcached/bin/memcached -p 11211 -l 127.0.0.1 -d -u nobody -P /var/run/memcached.pid -m 64M -c 1024

几个参数的解释:
-p memcached监听的TCP端口
-l 监听的ip地址,127.0.0.1是本机,当然也可以写上你的服务器IP,如:61.150.91.26,这是我服务器的IP地址,如果你需要多个服务器都能够读取这台memcached的缓存数据,那么就必须设定这个ip
-d 以daemon方式运行,将程序放入后台
-u memcached的运行用户,我设定的是nobody
-P memcached的pid文件路径
-m memcached可以使用的最大内存数量
-c memcached同时可以接受的最大的连接数
如果你希望以socket方式来访问memcached,那么在启动的时候就必须去掉 -l和-p参数,并加上-s参数:
-s memcached的socket文件路径

启动mephp-fpm和nginx


  • ulimit -SHn 65535
  • /usr/local/php/sbin/php-fpm
  • /usr/local/nginx/sbin/nginx

复制代码
  以将这3条语句写入/etc/rc.local文件,
这样每次开机就可以启动php-fpm和nginx了。

优化Linux内核参数

  • vi /etc/sysctl.conf

复制代码
  在文件末尾增加以下内容:


  • # append
  • net.ipv4.tcp_max_syn_backlog = 65536
  • net.core.netdev_max_backlog = 32768
  • net.core.somaxconn = 32768

  • net.core.wmem_default = 8388608
  • net.core.rmem_default = 8388608
  • net.core.rmem_max = 16777216
  • net.core.wmem_max = 16777216

  • net.ipv4.tcp_timestamps = 0
  • net.ipv4.tcp_synack_retries = 2
  • net.ipv4.tcp_syn_retries = 2
  • net.ipv4.tcp_tw_recycle = 1
  • #net.ipv4.tcp_tw_len = 1
  • net.ipv4.tcp_tw_reuse = 1
  • net.ipv4.tcp_mem = 94500000 915000000 927000000
  • net.ipv4.tcp_max_orphans = 3276800

  • #net.ipv4.tcp_fin_timeout = 30
  • #net.ipv4.tcp_keepalive_time = 120
  • net.ipv4.ip_local_port_range = 1024 65535


复制代码
  使配置立即生效:

  • /sbin/sysctl -p

复制代码
  六. References & thanks
 http://blog.s135.com/nginx_php_v6/
 http://blog.csdn.net/shagoo/archive/2008/08/05/2772418.aspx
 http://php-fpm.org/download/
 http://janwer.javaeye.com/blog/210952
 http://blog.iyunv.com/u/31547/showart_493408.html
 http://www.yanghengfei.com/archives/294/
 http://bbs.linuxsky.org/thread-5561-1-1.html

运维网声明 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-215968-1-1.html 上篇帖子: linux安装软件时提示找不到镜像的问题:Couldn't resolve host 'mirrorlist.centos.org' 下篇帖子: 又见乱码——CentOS下JFreeChart生成图片的中文乱码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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