编译安装LNMP(Linux+Nginx+Mysql+PHP+Memcache)服务器
最近学习了一段时间的LNMP和Nginx的负载均衡方面的内容,并且试着自己编译了几个生产环境,使用效果还不错,今天首先把这次安装配置的流水账先写下来,等消化一下具体内容,在好好写一份详细的LNMP编译安装配置的文章:
一、系统安装升级
1.最小化安装CentOS(最小化安装CentOS可以参考www.tisswb/archives/519.html
2.更新源更改为搜狐的源:mirrors.sohu
3.yum update
4.服务器基本配置
yum install setuptool ntsysv ntp vixie-cron crontabs microcode_ctl wget irqbalance vim-enhanced
5.执行setup命令
5.1 关闭iptables和selinux
5.2 仅仅开启crond irqbalance microcode_ctl network sshd syslog
二、LNMP环境搭建
1.配置编译需要的环境
yum -y install autoconf bzip2 bzip2-devel curl curl-devel e2fsprogs e2fsprogs-devel freetype freetype-devel gcc gcc-c++ gcc-g77 gd gd-devel glib2 glib2-devel glibc glibc-devel krb5 krb5-devel libevent libevent-devel libidn libidn-devel libjpeg libjpeg-devel libpng libpng10 libpng10-devel libpng-devel libtool libtool-libs libxml2 libxml2-devel make ncurses ncurses-devel nss_ldap openldap openldap-clients openldap-devel openldap-servers openssl openssl-devel patch pspell-devel zlib zlib-devel
2.下载所需要安装的软件
wget blog.s135/soft/linux/nginx_php/nginx/nginx-0.8.
wget blog.s135/soft/linux/nginx_php/php/php-5.2.
wget blog.s135/soft/linux/nginx_php/phpfpm/php-5.2.13-fpm-0.5.
wget blog.s135/soft/linux/nginx_php/mysql/mysql-5.1.
wget blog.s135/soft/linux/nginx_php/libiconv/libiconv-1.
wget blog.s135/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.
wget blog.s135/soft/linux/nginx_php/mcrypt/mcrypt-2.6.
wget blog.s135/soft/linux/nginx_php/memcache/memcache-2.
wget blog.s135/soft/linux/nginx_php/mhash/mhash-0.9.9.
wget blog.s135/soft/linux/nginx_php/pcre/pcre-8.
wget blog.s135/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.tar.bz2
3.安装PHP 5.2.13(FastCGI模式)
3.1编译安装PHP 5.2.13所需的支持库
tar zxvf libiconv-1.
cd libiconv-1.13/
./configure –prefix=/usr/local
make
make install
cd ../
tar zxvf libmcrypt-2.5.
cd libmcrypt-2.5.8/
.
/configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure –enable-ltdl-install
make
make install
cd ../../
tar zxvf mhash-0.9.9.
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
tar zxvf mcrypt-2.6.
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
3.2编译安装MySQL 5.1.38
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.1.
cd mysql-5.1.38/
./configure –prefix=/usr/local/webserver/mysql/ –enable-assembler –with-extra-charsets=complex –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=innobase
make && make install
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cd ../
如果你想在这台服务器上运行MySQL数据库,则执行以下两步。如果你只是希望让PHP支
持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
3.2.1创建MySQL数据库存放目录
mkdir -p /data0/mysql/3306/data/
chown -R mysql:mysql /data0/mysql/
3.2.2以mysql用户帐号的身份建立数据表
/usr/local/webserver/mysql/bin/mysql_install_db –basedir=/usr/local/webserver/mysql –datadir=/data0/mysql/3306/data –user=mysql
3.2.3创建myf配置文件
[client]
default-character-set = utf8
port    = 3306
socket  = /tmp/mysql.sock
[mysql]
#prompt=”(\u:blog.s135:)[\d]> ”
no-auto-rehash
[mysqld]
#default-character-set = utf8
user    = mysql
port    = 3306
socket  = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /data0/mysql/3306/data
open_files_limit    = 10240
back_log = 600
max_connections = 3000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 32M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 1
log_long_format
log-bin = /data0/mysql/3306/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
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_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
skip-name-resolve
master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
server-id = 1
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2048M
innodb_data_file_path = ibdata1:1024M: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
[mysqldump]
quick
max_allowed_packet = 32M
3.2.4创建管理MySQL数据库的shell脚本:
vi /data0/mysql/3306/mysql
#!/bin/sh
mysql_port=3306
mysql_username=”admin”
mysql_password=”asdasdasd”
function_start_mysql()
{
printf “Starting MySQL…\n”
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe –defaults-file=/data0/mysql/${mysql_p
ort}/myf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf “Stoping MySQL…\n”
/usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}
function_restart_mysql()
{
printf “Restarting MySQL…\n”
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9 $(ps -ef | grep ‘bin/mysqld_safe’ | grep ${mysql_port} | awk ‘{printf $2}’)
kill -9 $(ps -ef | grep ‘libexec/mysqld’ | grep ${mysql_port} | awk ‘{printf $2}’)
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf “Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n”
fi
3.2.5 赋予shell脚本可执行权限
chmod +x /data0/mysql/3306/mysql
3.2.6 启动MySQL
/data0/mysql/3306/mysql start
3.2.7 通过命令行登录管理MySQL服务器(提示输入密码时直接回车):
/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
3.2.8 输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(asdasdasd):
GRANT ALL PRIVILEGES ON *.* TO ‘admin’@'localhost’ IDENTIFIED BY ‘asdasdasd’;
GRANT ALL PRIVILEGES ON *.* TO ‘admin’@’127.0.0.1′ IDENTIFIED BY ‘asdasdasd’;
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’192.168.%.%’ IDENTIFIED BY ‘asdasdasd’;
3.2.9 停止MySQL
/data0/mysql/3306/mysql stop
3.3 编译安装PHP(FastCGI模式)
tar zxvf php-5.2.
gzip -cd php-5.2.13-fpm-0.5. | patch -d php-5.2.13 -p1
cd php-5.2.13/
./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-mysql=/usr/local/webserver/mysql –with-mysqli=/usr/local/webserver/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
mysql下载starting the server
cd ../
3.4 编译安装PHP5扩展模块
tar zxvf memcache-2.
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
tar jxvf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6/
/usr/local/webserver/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
3.5 修改php.ini文件
手工修改:查/usr/local/webserver/php/etc/php.ini中的extension_dir = “./”
修改为extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/”
并在此行后增加以下几行,然后保存:
extension = “memcache.so”
再查output_buffering = Off
修改为output_buffering = On
3.6 配置eAccelerator加速PHP
mkdir -p /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini
按shift+g键跳到配置文件的最末尾,加上以下配置信息:
[eaccelerator]
zend_extension=”/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/usr/local/webserver/eaccelerator_cache”
able=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eacceleratorpress=”1″
eacceleratorpress_level=”9″
3.7 创建www用户和组
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
3.8创建php-fpm配置文件
在/usr/local/webserver/php/etc/目录中创建f文件
rm -f /usr/local/webserver/php/f
vi /usr/local/webserver/php/f

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。