分享我的生活
分享能使人快乐

学习张大师,模仿要谨慎

话说在11号买了个512的vps,整整折腾了四天才折腾凑合着能用,究其原因,学业不精,见识有限所致。话说买完当日,上家直接给选的是ubuntu9.10,要知道centos和ubuntu的vps安装是有些不同的,尤其是编译安装,结果因为vsftpd,从头再来了一回。
换为centos,一路大大小小的问题,终于安装完毕,可是,启动nginx,php-fcgi,mysql,vsftpd,然后打开导入的网站,一开始绝对没有问题,而且网速还算可以,不过下次ssh就会有个问题,无法ssh登录了(错误代码:

ssh_exchange_identification: Connection closed by remote host

)。然后重启vps,刚开始可以ssh,连续点击十几个网页后,再进行ssh就会出现同样的错误。
于是我的目光一直盯在最后弄好的mysql上,难道是mysql捣乱?
索性,我按128m的vps的设置配好了mysql,可视还是不行。一天早上,看到一篇文章,一个php-cgi进程要缓存20m内存,天哪,我开了64个php-cgi,这需要1g多的内存,怪不得ssh进去以后都会出现cannot locate memery,把php-cgi进程改为14,重启进程,一切ok,可怜我那数据库是按128m内存配置的。
回过头来我们看看张大师的配置

[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/webserver/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/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 = /data0/mysql/3306/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /data0/mysql/3306/relaylog/relaylog
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/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 = /data0/mysql/3306/slow.log
#long_query_time = 10

[mysqldump]
quick
max_allowed_packet = 32M

这是数据库的配置,经常是512  200多的来

<configuration>

All relative paths in this config are relative to php’s install prefix

<section name=”global_options”>

Pid file
<value name=”pid_file”>/usr/local/webserver/php/logs/php-fpm.pid</value>

Error log file
<value name=”error_log”>/usr/local/webserver/php/logs/php-fpm.log</value>

Log level
<value name=”log_level”>notice</value>

When this amount of php processes exited with SIGSEGV or SIGBUS …
<value name=”emergency_restart_threshold”>10</value>

… in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator’s shared memory.
<value name=”emergency_restart_interval”>1m</value>

Time limit on waiting child’s reaction on signals from master
<value name=”process_control_timeout”>5s</value>

Set to ‘no’ to debug fpm
<value name=”daemonize”>yes</value>

</section>

<workers>

<section name=”pool”>

Name of pool. Used in logs and stats.
<value name=”name”>default</value>

Address to accept fastcgi requests on.
Valid syntax is ‘ip.ad.re.ss:port’ or just ‘port’ or ‘/path/to/unix/socket’
<value name=”listen_address”>127.0.0.1:9000</value>

<value name=”listen_options”>

Set listen(2) backlog
<value name=”backlog”>-1</value>

Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.
<value name=”owner”></value>
<value name=”group”></value>
<value name=”mode”>0666</value>
</value>

Additional php.ini defines, specific to this pool of workers.
<value name=”php_defines”>
<value name=”sendmail_path”>/usr/sbin/sendmail -t -i</value>
<value name=”display_errors”>0</value>
</value>

Unix user of processes
<value name=”user”>www</value>

Unix group of processes
<value name=”group”>www</value>

Process manager settings
<value name=”pm”>

Sets style of controling worker process count.
Valid values are ’static’ and ‘apache-like’
<value name=”style”>static</value>

Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
<value name=”max_children”>64</value>

Settings group for ‘apache-like’ pm style
<value name=”apache_like”>

Sets the number of server processes created on startup.
Used only when ‘apache-like’ pm_style is selected
<value name=”StartServers”>20</value>

Sets the desired minimum number of idle server processes.
Used only when ‘apache-like’ pm_style is selected
<value name=”MinSpareServers”>5</value>

Sets the desired maximum number of idle server processes.
Used only when ‘apache-like’ pm_style is selected
<value name=”MaxSpareServers”>35</value>

</value>

</value>

The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when ‘max_execution_time’ ini option does not stop script execution for some reason
‘0s’ means ‘off’
<value name=”request_terminate_timeout”>0s</value>

The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
‘0s’ means ‘off’
<value name=”request_slowlog_timeout”>0s</value>

The log file for slow requests
<value name=”slowlog”>logs/slow.log</value>

Set open file desc rlimit
<value name=”rlimit_files”>65535</value>

Set max core size rlimit
<value name=”rlimit_core”>0</value>

Chroot to this directory at the start, absolute path
<value name=”chroot”></value>

Chdir to this directory at the start, absolute path
<value name=”chdir”></value>

Redirect workers’ stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
<value name=”catch_workers_output”>yes</value>

How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
<value name=”max_requests”>1024</value>

Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
<value name=”allowed_clients”>127.0.0.1</value>

Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
<value name=”environment”>
<value name=”HOSTNAME”>$HOSTNAME</value>
<value name=”PATH”>/usr/local/bin:/usr/bin:/bin</value>
<value name=”TMP”>/tmp</value>
<value name=”TMPDIR”>/tmp</value>
<value name=”TEMP”>/tmp</value>
<value name=”OSTYPE”>$OSTYPE</value>
<value name=”MACHTYPE”>$MACHTYPE</value>
<value name=”MALLOC_CHECK_”>2</value>
</value>

</section>

</workers>

</configuration>

这是php-fpm,他自己开了128进程,建议不足3g内存的童鞋开64进程,结果就出现ssh不能登录,输入命令不能获得内存的错误。
最后看看nginx的
一下开了8个进程,每个进程15–20m,这又是100多m的内存,我们128,256,512的小vps,这根本不是我们考虑的。
最后总结,我们学习,尤其是跟着别人学习,本不应该抱怨,但是我们应该细心,看看别人的配置和我们的配置差多少,不然你一定很头疼别人弄的很好自己却不能如愿以偿。自己看着我的内容自己改吧。

赞(0)
未经允许不得转载:RUBLOG-分享我的生活 » 学习张大师,模仿要谨慎

我想说 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址