优化LNMP架构采用“Website Baker”为小型公司创建高性能网站方案参考图片1.
一、安装部署各种软件:
1.系统环境:
硬件:HP 360G4/2G
System:Centos 5.4
Web:nginx-1.1.6.tar.gz
FastCGI:php-5.3.8.tar.gz
DB:mysql-5.5.3-m3.tar.gz
2. 安装编译环境
#yum -y install gcc gcc-c++ autoconf automake openssl-devel zlib-devel pcre-devel //pcre让nginx支持正则
#yum -yt groupinstall "Developement Tools" "Development Libraries" 1.编译安装mysql
//a.编译安装mysql的优点:源码包的默认编译参数默认以dubgu模式)给mysql的性能带来很大的损失,
// 此处使用 --without-debug参数禁用debug模式
//b.以静态方式编译(比动态方式提高5%-10%的性能)
// 此处使用 --with-mysqld-ldflgs=--all-staic 和 --with-client-ldflds=--all-staic参数
//c.使用unix套接字链接提高7.5%性能
// 此处使用--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
//d.允许使用汇编模式
// 此处使用 --enable-assembler (优化性能)
//e.至于 --pgcc 目前没有在生产上使用过(据说可以提高1%)
//f.编译安装,可以在同一台服务器上安装多个mysql(前提要保证存放位置、sock不同)
#groupadd mysql //为mysql创建用户组
#useradd -g mysql mysql //将mysql用户添加到mysql组中
#tar zxvf mysql-5.5.3-m3.tar.gz
#cd mysql-5.5.3-m3
./configure \
--prefix=/usr/local/mysql \
--without-debug \ //取消debug模式编译
--enable-assembler \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \
--with-extra-charsets=utf8,gbk //如果没有问题则会显示
// Thank you for choosing MySQL!
// 以下时间将为很长,请为mysql创建配置文件或数据目录
#make && make install //如果编译安装没有问题则NEXT
#chmod 755 /usr/local/mysql
#chown -R mysql:mysql /usr/local/mysql //修改安装目录的用户和用户组为mysql
#mkdir -pv /mysql_data/{data,binlog,relaylog} //为mysql提供数据存放目录
#/usr/local/mysql/bin/mysql_install_db \ //推荐是用其它新分区,避免IO重读/分区
--basedir=/usr/local/mysql \
--datadir=/mysql_data --user=mysql
----------------------------------------------
//创建并优化my.cnf文件
#vi /mysql_data/my.cnf //创建后保存
[client]
character-set-server = utf8
port = 3306
socket = /usr/local/mysql/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 = /usr/local/mysql/tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /mysql_data/data
log-error = /mysql_data/mysql.error.log
pid-file = /mysql_data/mysql.pid
skip-locking //避免mysql外部锁定
open_files_limit = 10240
back_log = 384 //推荐小于512
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
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 = /mysql_data/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /mysql_data/relaylog/relaylog
relay-log-info-file = /mysql_data/relaylog/relaylog
relay-log = /mysql_data/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M //索引缓冲区为256M 或(4G内存可512M)
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 //避免做DNS 解析,提供IP地址连接 slave-skip-errors = 1032,1062,126,1114,1146,1048,1396