把之前一直惦记的民间传说性能超Apache N倍的NGINX玩了下。研究+测试前后就是一个下午时间,在此把自己的心得整理了下。
(最后的备注为介绍NGINX加载PHP原理)
Linux操作系统:CentOS 6.3 64bit
NGINX:nginx-1.4.0
MySQL:mysql-5.6.10
PHP:php-5.4.13
一.安装开发包(使用默认CENTOS更新源):
# yum -y install wget gcc-c++ ncurses-devel cmake make perl
二.关闭iptables和SELINUX
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
---------------
三.安装mysql数据库
# wget ://cdn.mysql.com/
# useradd -d /usr/local/mysql/ mysql 创建一个Mysql用户,指定家目录到/use/local目录下。
# mkdir /usr/local/mysql/data
# mkdir /usr/local/mysql/log 新建一个目录
# chown -R mysql:mysql /usr/local/mysql/data/
# chown -R mysql:mysql /usr/local/mysql/log/
# chmod 750 /usr/local/mysql/data
# chmod 750 /usr/local/mysql/log 修改目录的所属者以及所属组
# tar -zxv -f mysql-5.6.10.tar.gz 解包
# cd mysql-5.6.10
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DDEFAULT_CHARSET=gbk \
-DDEFAULT_COLLATION=gbk_chinese_ci \
-DEXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
# make
# make install
# 复制配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
# vi /etc/my.cnf
--------------------------------------
[mysql]
# CLIENT #
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
# GENERAL #
user = mysql
default_storage_engine = InnoDB
socket = /var/lib/mysql/mysql.sock
pid_file = /var/run/mysqld/mysqld.pid
# MyISAM #
key_buffer_size = 32M
myisam_recover = FORCE,BACKUP
# SAFETY #
max_allowed_packet = 16M
max_connect_errors = 1000000
skip_name_resolve
sql_mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
sysdate_is_now = 1
innodb = FORCE
innodb_strict_mode = 1
# DATA STORAGE #
datadir = /usr/local/mysql/data
# BINARY LOGGING #
log-bin =/usr/local/mysql/log/bin.log
expire_logs_days = 30
sync_binlog = 1
# CACHES AND LIMITS #
key_buffer = 256M
max_allowed_packet = 64M
sort_buffer_size = 256M
read_buffer_size = 256M
read_rnd_buffer_size = 256M
thread_stack = 256M
tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 256M
max_connections = 2048
thread_cache_size = 512
open_files_limit = 65535
table_definition_cache = 1024
table_open_cache = 2048
# INNODB #
innodb_log_files_in_group = 2
innodb_log_file_size = 64M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table = 1
innodb_buffer_pool_size = 2G
# LOGGING #
log-error=/usr/local/mysql/log/error.log
general_log=1
general_log_file=/usr/local/mysql/log/mysql.log
slow_query_log=1
slow_query_log_file=/usr/local/mysql/log/slowquery.log
log-output=FILE
# 避免MySQL的外部锁定,减少出错几率增强稳定性 #
skip-external-locking
# 禁止sql读取本地文件 #
local-infile=0
-------------------------------------
# 进入安装路径
cd /usr/local/mysql
# 执行配置脚本
scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
# 复制服务启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld #添加开机启动服务
# chkconfig --level 35 mysqld on #设置mysql启动
# service mysqld start #启动数据库
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 创建一个mysql接口的软链接
# /usr/local/mysql/bin/mysqladmin -u root password 123456 #设置密码
# /usr/local/mysql/bin/mysql -u root -p123456 #连接数据库
mysql> create database phpwind; #---创建数据库
mysql> grant all privileges on *.* to root@'%' identified by '123456' with grant option; #给root用户非本地链接所有权限,并改密码和赋予其给其他人下发权限.
mysql> show variables; #查看mysql设置.
# 这里是把mysql文件链接到默认位置,必须做这步,在编译其他软件的时候自定义mysql的库文件路径。
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
LNMP 全功能编译安装 for CentOS 6.3笔记
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/6ba9efbe2670b5511fcc0ab5c8c2699c.html