接上篇 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.chinaunix.net/u/31547/showart_493408.html
http://www.yanghengfei.com/archives/294/
http://bbs.linuxsky.org/thread-5561-1-1.html
发表评论
-
在linux网站运维方向老男孩最近几年常用的免费的开源软件
2013-02-18 23:35 1603http://blog.chinaunix.net/uid- ... -
rsync服务部署
2013-02-18 22:40 872http://oplinux.com/app/rsync/r ... -
centos6.0 配置SVN
2013-02-04 14:52 1002http://blog.csdn.net/tonysz12 ... -
Centos搭建SVN服务器三步曲
2013-02-04 12:09 918搭建SVN服务,有效的管理代码,以下三步可以快速搞定。1、安 ... -
linux(centos)如何使用svn进行多个版本库的配置
2013-02-04 12:08 3560如果当前有svnserve进程在运行,指令 ... -
php 实例说明 socket通信机制
2012-12-28 10:41 929http://blog.51yip.com/php/673.h ... -
php 利用socket上传文件
2012-12-28 10:40 1215http://blog.51yip.com/php/686.h ... -
MySQL CMake参数说明手册
2012-12-24 10:52 775http://www.sunchis.com/html/db/ ... -
Nginx下搭建flv视频服务器且支持视频拖动进度条播放
2012-12-19 18:10 1168目前,由于Flash 的流行,网络上绝大多数的微视频网站 ... -
Linux下Xdebug的编译安装及使用方法
2012-12-18 17:27 1630http://zhugebin.sinaapp.com/lin ... -
如何查询centos查看系统内核版本,系统版本,32位还是64位
2012-12-15 11:13 1231http://hi.baidu.com/tjbaso/item ... -
linux下磁盘I/O查看
2012-12-07 13:11 809http://zlbzhu.blog.51cto.co ... -
Centos5.5最小化安装后的优化
2012-11-20 23:16 1186购买了服务器(现在主流 ... -
CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.13+博客系统WordPress3.3.2
2012-11-11 23:37 1032说明: 操作系统:CentOS 6.2 32 ... -
CentOS minimal 版安装图形界面的步骤分享,中文语言包.
2012-11-11 22:33 7371、连接网络: CentOS minimal.iso安装好 ... -
CentOS 6.3编译安装Nginx1.2.2+MySQL5.5.25a+PHP5.4.5
2012-11-04 19:56 902说明: 操作系统:CentOS 6.3 32位 系 ... -
[HTML5]配置Ngnix服务器支持manifest 离线存储
2012-10-08 14:09 1430[HTML5]配 ... -
RSync实现文件备份同步
2012-09-21 12:20 773http://www.cnblogs.com/itech/ar ... -
CentOS 5 + rsync 同步2台服务器的文件
2012-09-21 12:11 871当需要把服务器上的文件复制到另外的机器上,可用rsync来同步 ... -
Linux下利用rsync实现多服务器文件同步
2012-09-21 12:07 937注意事项: 1、主服务器上有配置文件,从服务器上没有配置文件 ...
相关推荐
Windows8上安装虚拟机VirtualBox,然后新建虚拟电脑,搭建CentOS6.5 + mysql + nginx + php + memcached平台环境,部署网站。文档中记录了部分FAQ。
在本篇文章中,我们将详细探讨在CentOS环境下安装和配置Nginx 0.8.52、PHP 5.3.3、MySQL 5.5.6以及Memcached 1.4.5这一系列软件的过程,同时还会对配置进行优化以达到提升性能的目的。这些技术组件共同构成了一个...
### Nginx+Apache+MySQL+PHP+Memcached+Squid 搭建门户网站 #### 一、前言与架构概述 随着互联网技术的发展,如何构建一个高效、稳定且能够应对高并发访问的Web服务器成为了许多企业和开发者关注的重点。本文将...
例如,这里使用的是双核Intel Xeon 3.00GHz服务器,2GB内存,CentOS 4.4操作系统,以及一系列预安装的软件版本,如Apache 2.2.3、PHP 5.2.0、eAccelerator 0.9.5、memcache 1.2.0、MySQL 5.0.27、Nginx 0.5.4和Squid...
### CentOS Nginx PHP JAVA多语言镜像使用手册 #### 镜像说明 ##### 版本说明 根据文档中的信息,此镜像是一个专为阿里云设计的多语言环境镜像,支持多种版本的软件,包括但不限于: - **Nginx** 1.10.3:这是一...
在CentOS 7.2系统上安装Nginx 1.12、PHP 7.1和MySQL 5.6的步骤如下: 首先,为了获取额外的软件包,你需要添加EPEL(Extra Packages for Enterprise Linux)仓库源。运行以下命令: ```bash yum -y install epel-...
在本场景中,我们讨论的是基于Nginx、Apache、MySQL、PHP、Memcached和Squid构建的服务器集群。下面将详细解释这些组件及其在集群中的作用。 1. **Nginx**:Nginx是一个高性能的HTTP和反向代理服务器,以其轻量级和...
【吐血推荐】nginx+apache+mysql+php+memcached+squid搭建集群web环境(二) 此乃本人N次服务器真机实验所得,所以分数高点,望体谅.. 按教程来做,你也可以搭建linux服务器... 注:此乃分卷二,
### Linux+Apache+Nginx+MySQL+PHP (LANMP/LNAMP) 生产环境部署详解 #### 一、概述 本文旨在详细介绍如何构建一个高效、稳定的Linux+Apache+Nginx+MySQL+PHP(LANMP/LNAMP)生产环境。通过合理配置这些组件,可以...
本文将详细介绍如何从源码编译安装LNMP环境,具体包括Nginx 1.4.6、PHP 5.5.11、MySQL 5.6.17以及额外的Memcache和Opcache。 #### 三、编译前准备 1. **选择合适的Linux发行版**:推荐使用CentOS 6.4 x86_64位,...
本文将详细介绍如何在CentOS 6.5上安装LNMP(Linux+Nginx+MySQL+PHP)服务器环境。LNMP架构是一种非常流行的Web服务器组合,它不仅性能高效而且配置灵活,非常适合部署各种基于PHP的应用程序。 #### 二、准备阶段 ...
通过本文对Linux+Nginx+PHP+MySQL+Memcached技术栈的详细介绍,我们可以看出这一组合在构建高效稳定Web服务器方面具有明显优势。然而实际应用过程中还需根据具体情况进行适当调整与优化,以达到最佳效果。希望本文能...
本文详细介绍了在CentOS 7环境下安装Nextcloud所需的基础环境配置流程,包括Nginx、PHP及其扩展以及MySQL数据库的安装步骤。通过这些步骤,你可以为Nextcloud的安装打下坚实的基础。接下来,我们将继续探讨Nextcloud...
本教程将详细介绍如何在CentOS 7上使用YUM包管理器来安装LNMP环境,特别是针对Nginx 1.12+、PHP 7.1和MySQL 5.7的版本。 首先,确保系统是最新的,通过执行以下命令更新系统包: ```bash yum update ``` 接下来,...
**LANMP安装配置详解** 在IT行业中,LANMP(Linux + Apache + Nginx + MySQL/MariaDB + PHP)是一种常见的Web服务器架构,用于搭建高效、稳定且可扩展的网站平台。本文将深入探讨如何在CentOS操作系统上进行完整的...
### LAMP网站架构方案及安装配置详解 #### 一、LAMP架构概述 LAMP(Linux-Apache-MySQL-PHP)是一种广泛使用的网站架构框架,由以下四个主要部分组成: 1. **Linux**:作为操作系统,Linux因其开源性、稳定性和...
安装过程中还会自动安装编译Nginx、MySQL、PHP、phpMyAdmin和Zend Optimizer等软件。 安装完成后,你还可以通过额外的脚本安装其他组件,如PureFTPd、eAccelerator、ionCube、imageMagick和memcached,以增强Web...
在32位CentOS 5.x/6.0操作系统中配置KMP(Kangle MySQL PHP)涉及多个步骤,包括MySQL数据库、PHP解释器以及Kangle Web服务器的源码编译安装。以下是对整个过程的详细讲解: 1. **MySQL 5.1.x 和 5.5.x 编译方法**...
手册最后列出了所有软件的版本信息,包括Nginx 1.9.14、MySQL 5.6.29、Redis 3.0.7、Memcached 1.4.25、Jemalloc 4.1.0、Pure-FTPd 1.0.42、phpMyAdmin *.*.**.*。这些信息对于了解系统配置和后续的故障排查非常有用...
LNMP(Docker + Docker-compose + Nginx + MySQL5.7 + PHP7.2 + Redis5.0 + Memcached1.5 + Mongodb4.2) LNMP项目特点: 一键安装,简单实用 包含lnmp常用服务 各服务支持数据文件,配置文件,日志文件挂载 默认...