公司搞的测试环境正好拿来测试安装一下LNMP环境,用的软件是
nginx-1.0.14.tar.gz
mysql-5.5.22.tar.gz
php-5.4.0.tar.gz
这个环境只是开发人员用来测试的,生产环境用的不是最新
首先来更新一下程序所需要的库文件。
- yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
1.编译安装mysql-5.5.22
groupadd mysql
useradd -g mysql mysql -s /sbin/nologin
(1).编译安装mysql的编译器cmake
- tar -xf cmake-2.8.4.tar.gz
- ./configure
- make
- make install
(2)编译安装mysql
- tar -xf mysql-5.5.22.tar.gz
- cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1
- make
- make install
- cp support-files/my-medium.cnf /etc/my.cnf
- cp support-files/mysql.server /etc/rc.d/init.d/mysqld
(3)初始化mysql
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
/usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/data --user=mysql
在编译目录下有个mysql启动脚本,可以拿过来用一下
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
可以用这个来启动mysql
2.编译安装php-5.4.0所需的支持库
- (1)tar -xf libiconv-1.13.1.tar.gz
- ./configure --prefix=/usr/local
- make
- make install
- (2)tar -xf libmcrypt-2.5.8.tar.gz
- ./configure
- make
- make install
- /sbin/ldconfig
- cd libltdl/
- ./configure --enable-ltdl-install
- make
- make install
- (3)tar -xf mhash-0.9.9.9.tar.gz
- ./configure
- make
- make install
- 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
- (4)tar -xf mcrypt-2.6.8.tar.gz
- /sbin/ldconfig
- ./configure
- make
- make install
(5)编译安装php-5.4.0
- tar -xf php-5.4.0.tar.gz
- ./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-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --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
注:如果在编译php是报这个错可以试一下用这种方法解决一下
- 在编译php,make的时候出错:
- /root/dev/php-5.3.6/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
- make: *** [ext/phar/phar.php] Error 127
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
然后重新编译一下。
cp php.ini-production /usr/local/webserver/php/etc/php.ini
cp php-5.4.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
copy出来用就可以了,这个脚本可以start stop reload fpm就和5.2+的那个脚本一样了!
(6)编译安装php-5.4.0的扩展模块
- tar zxvf memcache-2.2.5.tgz
- 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
- tar jxvf eaccelerator-0.9.6.1.tar.bz2
- cd eaccelerator-0.9.6.1/
- /usr/local/webserver/php/bin/phpize
- ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
- make
- make install
- tar zxvf PDO_MYSQL-1.0.2.tgz
- cd PDO_MYSQL-1.0.2/
- /usr/local/webserver/php/bin/phpize
- ./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
- make
- make install
- tar zxvf ImageMagick.tar.gz
- cd ImageMagick-6.5.1-2/
- ./configure
- make
- make install
- tar zxvf imagick-2.3.0.tgz
- cd imagick-2.3.0/
- /usr/local/webserver/php/bin/phpize
- ./configure --with-php-config=/usr/local/webserver/php/bin/php-config
- make
- make install
在安装的时候eaccelerator-0.9.6.1.tar.bz2这个没有安装上然后启动php打开网站没有问题,不过少了一个加速器性能肯定会下降一些。
3.编译安装nginx-1.0.14
(1)编译安装一下pcre
tar zxvf pcre-8.10.tar.gz
./configure
make && make install
(2)编译安装nginx
tar zxvf nginx-1.0.14.tar.gz
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
根据自己的喜好创建一些目录,更改nginx的目录。不更改启动都在默认目录下
现在附上我们服务器上的nginx 及 mysql的配置文件
nginx.conf
- user www www;
- worker_processes 8;
- error_log /data/logs/nginx_error.log error;
- pid /usr/local/webserver/nginx/nginx.pid;
- #Specifies the value for maximum file descriptors that can be opened by this process.
- worker_rlimit_nofile 51200;
- events
- {
- use epoll;
- worker_connections 65535;
- }
- http
- {
- include mime.types;
- default_type application/octet-stream;
- #charset gb2312;
- server_names_hash_bucket_size 128;
- client_header_buffer_size 256k;
- large_client_header_buffers 8 256k;
- client_max_body_size 32m;
- sendfile on;
- tcp_nopush on;
- #send_timeout 60;
- server_tokens off;
- keepalive_timeout 10;
- tcp_nodelay on;
- ssi on;
- ssi_silent_errors on;
- ssi_types text/shtml;
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- fastcgi_buffer_size 64k;
- fastcgi_buffers 4 64k;
- fastcgi_busy_buffers_size 128k;
- fastcgi_temp_file_write_size 128k;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 16k;
- gzip_http_version 1.0;
- gzip_comp_level 2;
- gzip_types text/plain application/x-javascript text/css application/xml;
- gzip_vary on;
- #limit_zone crawler $binary_remote_addr 10m;
- include /usr/local/webserver/nginx/conf/vhosts/*.conf;
- }
my.cnf
- [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 = /data/mysql
- log-error = /data/mysql/mysql_error.log
- pid-file = /data/mysql/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-bin = /data/binlog
- binlog_cache_size = 4M
- binlog_format = MIXED
- max_binlog_cache_size = 8M
- max_binlog_size = 1G
- 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
- 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
- [mysqldump]
- quick
- max_allowed_packet = 32M
到此配置完了,有什么地方要改进的希望大家提出来,谢谢!