`

CentOS Nginx PHP MySQL Memcached 安装 配置 优化 (二)

阅读更多

接上篇  CentOS Nginx PHP MySQL Memcached 安装 配置 优化

四、配置篇
4.1 mysql配置

  1. mkdir -p /var/mysql/
  2. mkdir -p /var/mysql/data/
  3. mkdir -p /var/mysql/log/
  4. chown -R mysql:mysql /var/mysql/
  5. /usr/local/mysql/bin/mysql_install_db \
  6. --defaults-file=/var/mysql/my.cnf \
  7. --basedir=/usr/local/mysql \
  8. --datadir=/var/mysql/data \
  9. --user=mysql
  10. vi /var/mysql/my.cnf
复制代码

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


  1. [client]
  2. #character-set-server = utf8
  3. port = 3306
  4. socket = /tmp/mysql.sock
  5. [mysqld]
  6. character-set-server = utf8
  7. replicate-ignore-db = mysql
  8. replicate-ignore-db = test
  9. replicate-ignore-db = information_schema
  10. user = mysql
  11. port = 3306
  12. socket = /tmp/mysql.sock
  13. basedir = /usr/local/mysql
  14. datadir = /var/mysql/data
  15. log-error = /var/mysql/log/error.log
  16. pid-file = /var/mysql/mysql.pid
  17. open_files_limit = 10240
  18. back_log = 600
  19. max_connections = 5000
  20. max_connect_errors = 6000
  21. table_cache = 614
  22. external-locking = FALSE
  23. max_allowed_packet = 32M
  24. sort_buffer_size = 1M
  25. join_buffer_size = 1M
  26. thread_cache_size = 300
  27. #thread_concurrency = 8
  28. query_cache_size = 512M
  29. query_cache_limit = 2M
  30. query_cache_min_res_unit = 2k
  31. default-storage-engine = MyISAM
  32. thread_stack = 192K
  33. transaction_isolation = READ-COMMITTED
  34. tmp_table_size = 246M
  35. max_heap_table_size = 246M
  36. long_query_time = 3
  37. log-slave-updates
  38. log-bin = /var/mysql/log/binlog
  39. binlog_cache_size = 4M
  40. binlog_format = MIXED
  41. max_binlog_cache_size = 8M
  42. max_binlog_size = 1G
  43. relay-log-index = /var/mysql/log/relaylog
  44. relay-log-info-file = /var/mysql/log/relaylog
  45. relay-log = /var/mysql/log/relaylog
  46. expire_logs_days = 30
  47. key_buffer_size = 256M
  48. read_buffer_size = 1M
  49. read_rnd_buffer_size = 16M
  50. bulk_insert_buffer_size = 64M
  51. myisam_sort_buffer_size = 128M
  52. myisam_max_sort_file_size = 10G
  53. myisam_repair_threads = 1
  54. myisam_recover
  55. interactive_timeout = 120
  56. wait_timeout = 120
  57. skip-name-resolve
  58. #master-connect-retry = 10
  59. slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
  60. #master-host = 192.168.1.2
  61. #master-user = username
  62. #master-password = password
  63. #master-port = 3306

  64. server-id = 1
  65. innodb_additional_mem_pool_size = 16M
  66. innodb_buffer_pool_size = 512M
  67. innodb_data_file_path = ibdata1:256M:autoextend
  68. innodb_file_io_threads = 4
  69. innodb_thread_concurrency = 8
  70. innodb_flush_log_at_trx_commit = 2
  71. innodb_log_buffer_size = 16M
  72. innodb_log_file_size = 128M
  73. innodb_log_files_in_group = 3
  74. innodb_max_dirty_pages_pct = 90
  75. innodb_lock_wait_timeout = 120
  76. innodb_file_per_table = 0
  77. #log-slow-queries = /var/mysql/log/slow.log
  78. #long_query_time = 10
  79. [mysqldump] quick max_allowed_packet = 32M
复制代码

4.2 PHP配置

  1. vi /usr/local/php/etc/php.ini
复制代码

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

  1. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
  2. extension=apc.so
  3. extension=imagick.so
  4. extension=memcache.so
复制代码

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

  1. [APC]
  2. apc.enabled=1
  3. apc.ttl=7200
  4. apc.shm_size=32
复制代码

4.3 PHP-FPM配置

  1. cd /usr/local/php/etc/
  2. cp php-fpm.conf.default php-fpm.conf
  3. vi php-fpm.conf
复制代码

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


  1. ;;;;;;;;;;;;;;;;;;;;;
  2. ; FPM Configuration ;
  3. ;;;;;;;;;;;;;;;;;;;;;

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

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

  14. ;;;;;;;;;;;;;;;;;;
  15. ; Global Options ;
  16. ;;;;;;;;;;;;;;;;;;

  17. [global]
  18. ; Pid file
  19. ; Note: the default prefix is /usr/local/web/php/var
  20. ; Default Value: none
  21. ;pid = run/php-fpm.pid
  22. pid = /var/run/php-fpm.pid

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

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

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

  41. ; Log level
  42. ; Possible Values: alert, error, warning, notice, debug
  43. ; Default Value: notice
  44. ;log_level = notice

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

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

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

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

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

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

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

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

  93. ;;;;;;;;;;;;;;;;;;;;
  94. ; Pool Definitions ;
  95. ;;;;;;;;;;;;;;;;;;;;

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

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

  104. ; Per pool prefix
  105. ; It only applies on the following directives:
  106. ; - 'slowlog'
  107. ; - 'listen' (unixsocket)
  108. ; - 'chroot'
  109. ; - 'chdir'
  110. ; - 'php_values'
  111. ; - 'php_admin_values'
  112. ; When not set, the global prefix (or /usr/local/web/php) applies instead.
  113. ; Note: This directive can also be relative to the global prefix.
  114. ; Default Value: none
  115. ;prefix = /path/to/pools/$pool

  116. ; Unix user/group of processes
  117. ; Note: The user is mandatory. If the group is not set, the default user's group
  118. ;       will be used.
  119. user = www
  120. group = www
  121. ;user = nobody
  122. ;group = nobody

  123. ; The address on which to accept FastCGI requests.
  124. ; Valid syntaxes are:
  125. ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
  126. ;                            a specific port;
  127. ;   'port'                 - to listen on a TCP socket to all addresses on a
  128. ;                            specific port;
  129. ;   '/path/to/unix/socket' - to listen on a unix socket.
  130. ; Note: This value is mandatory.
  131. listen = 127.0.0.1:9000

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

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

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

  150. ; Choose how the process manager will control the number of child processes.
  151. ; Possible Values:
  152. ;   static  - a fixed number (pm.max_children) of child processes;
  153. ;   dynamic - the number of child processes are set dynamically based on the
  154. ;             following directives. With this process management, there will be
  155. ;             always at least 1 children.
  156. ;             pm.max_children      - the maximum number of children that can
  157. ;                                    be alive at the same time.
  158. ;             pm.start_servers     - the number of children created on startup.
  159. ;             pm.min_spare_servers - the minimum number of children in 'idle'
  160. ;                                    state (waiting to process). If the number
  161. ;                                    of 'idle' processes is less than this
  162. ;                                    number then some children will be created.
  163. ;             pm.max_spare_servers - the maximum number of children in 'idle'
  164. ;                                    state (waiting to process). If the number
  165. ;                                    of 'idle' processes is greater than this
  166. ;                                    number then some children will be killed.
  167. ;  ondemand - no children are created at startup. Children will be forked when
  168. ;             new requests will connect. The following parameter are used:
  169. ;             pm.max_children           - the maximum number of children that
  170. ;                                         can be alive at the same time.
  171. ;             pm.process_idle_timeout   - The number of seconds after which
  172. ;                                         an idle process will be killed.
  173. ; Note: This value is mandatory.
  174. pm = dynamic

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

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

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

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

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

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

  207. ; The URI to view the FPM status page. If this value is not set, no URI will be
  208. ; recognized as a status page. It shows the following informations:
  209. ;   pool                 - the name of the pool;
  210. ;   process manager      - static, dynamic or ondemand;
  211. ;   start time           - the date and time FPM has started;
  212. ;   start since          - number of seconds since FPM has started;
  213. ;   accepted conn        - the number of request accepted by the pool;
  214. ;   listen queue         - the number of request in the queue of pending
  215. ;                          connections (see backlog in listen(2));
  216. ;   max listen queue     - the maximum number of requests in the queue
  217. ;                          of pending connections since FPM has started;
  218. ;   listen queue len     - the size of the socket queue of pending connections;
  219. ;   idle processes       - the number of idle processes;
  220. ;   active processes     - the number of active processes;
  221. ;   total processes      - the number of idle + active processes;
  222. ;   max active processes - the maximum number of active processes since FPM
  223. ;                          has started;
  224. ;   max children reached - number of times, the process limit has been reached,
  225. ;                          when pm tries to start more children (works only for
  226. ;                          pm 'dynamic' and 'ondemand');
  227. ; Value are updated in real time.
  228. ; Example output:
  229. ;   pool:                 www
  230. ;   process manager:      static
  231. ;   start time:           01/Jul/2011:17:53:49 +0200
  232. ;   start since:          62636
  233. ;   accepted conn:        190460
  234. ;   listen queue:         0
  235. ;   max listen queue:     1
  236. ;   listen queue len:     42
  237. ;   idle processes:       4
  238. ;   active processes:     11
  239. ;   total processes:      15
  240. ;   max active processes: 12
  241. ;   max children reached: 0
  242. ;
  243. ; By default the status page output is formatted as text/plain. Passing either
  244. ; 'html', 'xml' or 'json' in the query string will return the corresponding
  245. ; output syntax. Example:
  246. ;   http://www.foo.bar/status
  247. ;   http://www.foo.bar/status?json
  248. ;   http://www.foo.bar/status?html
  249. ;   http://www.foo.bar/status?xml
  250. ;
  251. ; By default the status page only outputs short status. Passing 'full' in the
  252. ; query string will also return status for each pool process.
  253. ; Example:
  254. ;   http://www.foo.bar/status?full
  255. ;   http://www.foo.bar/status?json&full
  256. ;   http://www.foo.bar/status?html&full
  257. ;   http://www.foo.bar/status?xml&full
  258. ; The Full status returns for each process:
  259. ;   pid                  - the PID of the process;
  260. ;   state                - the state of the process (Idle, Running, ...);
  261. ;   start time           - the date and time the process has started;
  262. ;   start since          - the number of seconds since the process has started;
  263. ;   requests             - the number of requests the process has served;
  264. ;   request duration     - the duration in μs of the requests;
  265. ;   request method       - the request method (GET, POST, ...);
  266. ;   request URI          - the request URI with the query string;
  267. ;   content length       - the content length of the request (only with POST);
  268. ;   user                 - the user (PHP_AUTH_USER) (or '-' if not set);
  269. ;   script               - the main script called (or '-' if not set);
  270. ;   last request cpu     - the %cpu the last request consumed
  271. ;                          it's always 0 if the process is not in Idle state
  272. ;                          because CPU calculation is done when the request
  273. ;                          processing has terminated;
  274. ;   last request memory  - the max amount of memory the last request consumed
  275. ;                          it's always 0 if the process is not in Idle state
  276. ;                          because memory calculation is done when the request
  277. ;                          processing has terminated;
  278. ; If the process is in Idle state, then informations are related to the
  279. ; last request the process has served. Otherwise informations are related to
  280. ; the current request being served.
  281. ; Example output:
  282. ;   ************************
  283. ;   pid:                  31330
  284. ;   state:                Running
  285. ;   start time:           01/Jul/2011:17:53:49 +0200
  286. ;   start since:          63087
  287. ;   requests:             12808
  288. ;   request duration:     1250261
  289. ;   request method:       GET
  290. ;   request URI:          /test_mem.php?N=10000
  291. ;   content length:       0
  292. ;   user:                 -
  293. ;   script:               /home/fat/web/docs/php/test_mem.php
  294. ;   last request cpu:     0.00
  295. ;   last request memory:  0
  296. ;
  297. ; Note: There is a real-time FPM status monitoring sample web page available
  298. ;       It's available in: ${prefix}/share/fpm/status.html
  299. ;
  300. ; Note: The value must start with a leading slash (/). The value can be
  301. ;       anything, but it may not be a good idea to use the .php extension or it
  302. ;       may conflict with a real PHP file.
  303. ; Default Value: not set
  304. pm.status_path = /status

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

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

  320. ; The access log file
  321. ; Default: not set
  322. ;access.log = log/$pool.access.log

  323. ; The access log format.
  324. ; The following syntax is allowed
  325. ;  %%: the '%' character
  326. ;  %C: %CPU used by the request
  327. ;      it can accept the following format:
  328. ;      - %{user}C for user CPU only
  329. ;      - %{system}C for system CPU only
  330. ;      - %{total}C  for user + system CPU (default)
  331. ;  %d: time taken to serve the request
  332. ;      it can accept the following format:
  333. ;      - %{seconds}d (default)
  334. ;      - %{miliseconds}d
  335. ;      - %{mili}d
  336. ;      - %{microseconds}d
  337. ;      - %{micro}d
  338. ;  %e: an environment variable (same as $_ENV or $_SERVER)
  339. ;      it must be associated with embraces to specify the name of the env
  340. ;      variable. Some exemples:
  341. ;      - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
  342. ;      - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
  343. ;  %f: script filename
  344. ;  %l: content-length of the request (for POST request only)
  345. ;  %m: request method
  346. ;  %M: peak of memory allocated by PHP
  347. ;      it can accept the following format:
  348. ;      - %{bytes}M (default)
  349. ;      - %{kilobytes}M
  350. ;      - %{kilo}M
  351. ;      - %{megabytes}M
  352. ;      - %{mega}M
  353. ;  %n: pool name
  354. ;  %o: ouput header
  355. ;      it must be associated with embraces to specify the name of the header:
  356. ;      - %{Content-Type}o
  357. ;      - %{X-Powered-By}o
  358. ;      - %{Transfert-Encoding}o
  359. ;      - ....
  360. ;  %p: PID of the child that serviced the request
  361. ;  %P: PID of the parent of the child that serviced the request
  362. ;  %q: the query string
  363. ;  %Q: the '?' character if query string exists
  364. ;  %r: the request URI (without the query string, see %q and %Q)
  365. ;  %R: remote IP address
  366. ;  %s: status (response code)
  367. ;  %t: server time the request was received
  368. ;      it can accept a strftime(3) format:
  369. ;      %d/%b/%Y:%H:%M:%S %z (default)
  370. ;  %T: time the log has been written (the request has finished)
  371. ;      it can accept a strftime(3) format:
  372. ;      %d/%b/%Y:%H:%M:%S %z (default)
  373. ;  %u: remote user
  374. ;
  375. ; Default: "%R - %u %t \"%m %r\" %s"
  376. ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"

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

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

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

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

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

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

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

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

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

  429. ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
  430. ; the current environment.
  431. ; Default Value: clean env
  432. ;env[HOSTNAME] = $HOSTNAME
  433. ;env[PATH] = /usr/local/bin:/usr/bin:/bin
  434. ;env[TMP] = /tmp
  435. ;env[TMPDIR] = /tmp
  436. ;env[TEMP] = /tmp

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

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

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

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

4.3Nginx配置


  1. cd /usr/local/nginx/conf/
  2. cp nginx.conf.default nginx.conf
  3. vi nginx.conf
复制代码

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




  1. #user  nobody;
  2. user  www www;
  3. worker_processes  4;

  4. error_log  /var/log/nginx_error.log crit;
  5. #error_log  logs/error.log  notice;
  6. #error_log  logs/error.log  info;

  7. #pid        logs/nginx.pid;
  8. pid        /var/run/nginx.pid;


  9. events {
  10.     worker_connections  65535;
  11. }


  12. http {
  13.     include       mime.types;
  14.     default_type  application/octet-stream;

  15.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  16.     #                  '$status $body_bytes_sent "$http_referer" '
  17.     #                  '"$http_user_agent" "$http_x_forwarded_for"';

  18.     #access_log  logs/access.log  main;
  19.     charset utf-8;
  20.     server_names_hash_bucket_size 128;
  21.     client_header_buffer_size 32k;
  22.     large_client_header_buffers 4 32k;
  23.     client_max_body_size 8m;
  24.     sendfile on;
  25.     tcp_nopush on;

  26.     #tcp_nopush     on;

  27.     #keepalive_timeout  0;
  28.     keepalive_timeout  65;

  29.     tcp_nodelay on;
  30.     fastcgi_connect_timeout 300;
  31.     fastcgi_send_timeout 300;
  32.     fastcgi_read_timeout 300;
  33.     fastcgi_buffer_size 64k;
  34.     fastcgi_buffers 4 64k;
  35.     fastcgi_busy_buffers_size 128k;
  36.     fastcgi_temp_file_write_size 128k;
  37.     #gzip  on;
  38.     gzip on;
  39.     gzip_min_length 1k;
  40.     gzip_buffers 4 16k;
  41.     gzip_http_version 1.0;
  42.     gzip_comp_level 2;
  43.     gzip_types text/plain application/x-javascript text/css application/xml;
  44.     gzip_vary on;

  45.     server {
  46.         listen       80;
  47.         server_name  localhost;

  48.         index index.html index.htm index.php;
  49.         root /var/www;
  50.         #charset koi8-r;

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

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

  57.         #error_page  404              /404.html;

  58.         # redirect server error pages to the static page /50x.html
  59.         #
  60.         error_page   500 502 503 504  /50x.html;
  61.         location = /50x.html {
  62.             root   html;
  63.         }

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

  69.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  70.         #
  71.         #location ~ \.php$ {
  72.         #    root           html;
  73.         #    fastcgi_pass   127.0.0.1:9000;
  74.         #    fastcgi_index  index.php;
  75.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
  76.         #    include        fastcgi_params;
  77.         #}

  78.         # deny access to .htaccess files, if Apache's document root
  79.         # concurs with nginx's one
  80.         #
  81.         #location ~ /\.ht {
  82.         #    deny  all;
  83.         #}
  84.         log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  85.                 '$status $body_bytes_sent "$http_referer" '
  86.                 '"$http_user_agent" "$http_x_forwarded_for"';

  87.         access_log  /var/log/access.log  main;
  88.     }


  89.     # another virtual host using mix of IP-, name-, and port-based configuration
  90.     #
  91.     #server {
  92.     #    listen       8000;
  93.     #    listen       somename:8080;
  94.     #    server_name  somename  alias  another.alias;

  95.     #    location / {
  96.     #        root   html;
  97.     #        index  index.html index.htm;
  98.     #    }
  99.     #}


  100.     # HTTPS server
  101.     #
  102.     #server {
  103.     #    listen       443;
  104.     #    server_name  localhost;

  105.     #    ssl                  on;
  106.     #    ssl_certificate      cert.pem;
  107.     #    ssl_certificate_key  cert.key;

  108.     #    ssl_session_timeout  5m;

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

  112.     #    location / {
  113.     #        root   html;
  114.     #        index  index.html index.htm;
  115.     #    }
  116.     #}

  117. }
复制代码

五、启动篇
启动MySQL


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

启动memcached


  1. chmod 0777 /var/run ←允许普通用户程序写入pid文件
  2. /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


  1. ulimit -SHn 65535
  2. /usr/local/php/sbin/php-fpm
  3. /usr/local/nginx/sbin/nginx
复制代码

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

优化Linux内核参数

  1. vi /etc/sysctl.conf
复制代码

在文件末尾增加以下内容:


  1. # append
  2. net.ipv4.tcp_max_syn_backlog = 65536
  3. net.core.netdev_max_backlog = 32768
  4. net.core.somaxconn = 32768

  5. net.core.wmem_default = 8388608
  6. net.core.rmem_default = 8388608
  7. net.core.rmem_max = 16777216
  8. net.core.wmem_max = 16777216

  9. net.ipv4.tcp_timestamps = 0
  10. net.ipv4.tcp_synack_retries = 2
  11. net.ipv4.tcp_syn_retries = 2
  12. net.ipv4.tcp_tw_recycle = 1
  13. #net.ipv4.tcp_tw_len = 1
  14. net.ipv4.tcp_tw_reuse = 1
  15. net.ipv4.tcp_mem = 94500000 915000000 927000000
  16. net.ipv4.tcp_max_orphans = 3276800

  17. #net.ipv4.tcp_fin_timeout = 30
  18. #net.ipv4.tcp_keepalive_time = 120
  19. net.ipv4.ip_local_port_range = 1024 65535

复制代码

使配置立即生效:

  1. /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

分享到:
评论

相关推荐

    CentOS6.5+mysql+nginx+php+memcached安装指南

    Windows8上安装虚拟机VirtualBox,然后新建虚拟电脑,搭建CentOS6.5 + mysql + nginx + php + memcached平台环境,部署网站。文档中记录了部分FAQ。

    CentOS下Nginx0.8.52-PHP5.3.3-MySQL5.5.6-Memcached1.4.5安装配置优化

    在本篇文章中,我们将详细探讨在CentOS环境下安装和配置Nginx 0.8.52、PHP 5.3.3、MySQL 5.5.6以及Memcached 1.4.5这一系列软件的过程,同时还会对配置进行优化以达到提升性能的目的。这些技术组件共同构成了一个...

    nginx+apache+mysql+php+memcached+squid搭建门户网站

    ### Nginx+Apache+MySQL+PHP+Memcached+Squid 搭建门户网站 #### 一、前言与架构概述 随着互联网技术的发展,如何构建一个高效、稳定且能够应对高并发访问的Web服务器成为了许多企业和开发者关注的重点。本文将...

    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多语言镜像使用手册

    ### CentOS Nginx PHP JAVA多语言镜像使用手册 #### 镜像说明 ##### 版本说明 根据文档中的信息,此镜像是一个专为阿里云设计的多语言环境镜像,支持多种版本的软件,包括但不限于: - **Nginx** 1.10.3:这是一...

    Nginx1.12+PHP7.1+Mysql5.6.doc

    在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服务器集群.zip_nginx正向代理

    在本场景中,我们讨论的是基于Nginx、Apache、MySQL、PHP、Memcached和Squid构建的服务器集群。下面将详细解释这些组件及其在集群中的作用。 1. **Nginx**:Nginx是一个高性能的HTTP和反向代理服务器,以其轻量级和...

    nginx+apache+mysql+php+memcached+squid搭建集群web环境(二)

    【吐血推荐】nginx+apache+mysql+php+memcached+squid搭建集群web环境(二) 此乃本人N次服务器真机实验所得,所以分数高点,望体谅.. 按教程来做,你也可以搭建linux服务器... 注:此乃分卷二,

    Linux+Apache+Nginx+MySQL+PHP_前后端_部署_生产环境

    ### Linux+Apache+Nginx+MySQL+PHP (LANMP/LNAMP) 生产环境部署详解 #### 一、概述 本文旨在详细介绍如何构建一个高效、稳定的Linux+Apache+Nginx+MySQL+PHP(LANMP/LNAMP)生产环境。通过合理配置这些组件,可以...

    LNMP之nginx1.4.6+php5.5.11+mysql5.6.17+mecache+opcache编译安装

    本文将详细介绍如何从源码编译安装LNMP环境,具体包括Nginx 1.4.6、PHP 5.5.11、MySQL 5.6.17以及额外的Memcache和Opcache。 #### 三、编译前准备 1. **选择合适的Linux发行版**:推荐使用CentOS 6.4 x86_64位,...

    centos6.5安装LNMP服务器教程

    本文将详细介绍如何在CentOS 6.5上安装LNMP(Linux+Nginx+MySQL+PHP)服务器环境。LNMP架构是一种非常流行的Web服务器组合,它不仅性能高效而且配置灵活,非常适合部署各种基于PHP的应用程序。 #### 二、准备阶段 ...

    Linux+nginx+php+mysql+memcache

    通过本文对Linux+Nginx+PHP+MySQL+Memcached技术栈的详细介绍,我们可以看出这一组合在构建高效稳定Web服务器方面具有明显优势。然而实际应用过程中还需根据具体情况进行适当调整与优化,以达到最佳效果。希望本文能...

    Centos7系统安装nextcloud13.0.6,详细教程

    本文详细介绍了在CentOS 7环境下安装Nextcloud所需的基础环境配置流程,包括Nginx、PHP及其扩展以及MySQL数据库的安装步骤。通过这些步骤,你可以为Nextcloud的安装打下坚实的基础。接下来,我们将继续探讨Nextcloud...

    centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)

    本教程将详细介绍如何在CentOS 7上使用YUM包管理器来安装LNMP环境,特别是针对Nginx 1.12+、PHP 7.1和MySQL 5.7的版本。 首先,确保系统是最新的,通过执行以下命令更新系统包: ```bash yum update ``` 接下来,...

    LANMP安装配置

    **LANMP安装配置详解** 在IT行业中,LANMP(Linux + Apache + Nginx + MySQL/MariaDB + PHP)是一种常见的Web服务器架构,用于搭建高效、稳定且可扩展的网站平台。本文将深入探讨如何在CentOS操作系统上进行完整的...

    centos6.2+lnmp一键安装包+discuz论坛安装教程

    安装过程中还会自动安装编译Nginx、MySQL、PHP、phpMyAdmin和Zend Optimizer等软件。 安装完成后,你还可以通过额外的脚本安装其他组件,如PureFTPd、eAccelerator、ionCube、imageMagick和memcached,以增强Web...

    详细讲诉在32位centos 5.x6.0下配置kmp的方法.pdf

    在32位CentOS 5.x/6.0操作系统中配置KMP(Kangle MySQL PHP)涉及多个步骤,包括MySQL数据库、PHP解释器以及Kangle Web服务器的源码编译安装。以下是对整个过程的详细讲解: 1. **MySQL 5.1.x 和 5.5.x 编译方法**...

    Nginx镜像使用手册

    手册最后列出了所有软件的版本信息,包括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 *.*.**.*。这些信息对于了解系统配置和后续的故障排查非常有用...

    docker-lnmp:基于docker-compose构建的lnmp环境,包含php7,nginx,mysql,redis,memcached,mongodb,atlas,cron

    LNMP(Docker + Docker-compose + Nginx + MySQL5.7 + PHP7.2 + Redis5.0 + Memcached1.5 + Mongodb4.2) LNMP项目特点: 一键安装,简单实用 包含lnmp常用服务 各服务支持数据文件,配置文件,日志文件挂载 默认...

Global site tag (gtag.js) - Google Analytics