您的位置:首页 > 编程语言

lnmp环境安装-源代码编译

2014-11-27 17:06 543 查看
Lnmp安装配置(nginx)1.准备php函数的rpm包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-servers2.准备lnmp其他的源代码包wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz3.安装php-5.2.14源代码包所需要的函数支持包tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

tar zxvf mhash-0.9.9.9.tar.gz
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.8.tar.gz
cd mcrypt-2.6.8/./configure
make
make install
cd ../4. 编译安装MySQL 5.5.3-m3./configure --prefix=/usr/local/mysql --without-debug --enable-thread-safe-client --with-pthread --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-extra-charsets=all --with-plugins=all --with-mysqld-user=mysql --without-embedded-server --with-server-suffix=-community --with-unix-socket-path=/tmp/mysql.sockMake #编译Make install#安装1.cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf修改mysql配置文件1.[client]default-character-set=utf8#客户端字符集
#连接字符集2.[ mysqld]character-set-server = utf8#服务器字符集wwww#数据库字符集collation-server = utf8_general_ci#服务器,库,表的校验字符集#default-storage-engine=innodb#把默认的表引擎改为innodb* 生成MySQL配置文件 Useradd mysql Setfacl –m u:mysql:rwx –R /usr/local/mysql Setfacl –m d:u:mysql:rwx –R /usr/local/mysql * 用acl来让mysql用户对/usr/local/mysql有所有权限/usr/local/mysql/bin/mysql_install_db --user=mysql * 创建数据库授权表启动MySQL服务1.用原本源代码的方式去使用和启动mysql/usr/local/mysql/bin/mysqld_safe --user=mysql &2.重启以后还要生效:Vi /etc/rc.local/usr/local/mysql/bin/mysqld_safe --user=mysql &4./usr/local/mysql/bin/mysqladmin -uroot password kkk #给mysql用户root加密码.密码为kkk /usr/local/mysql/bin/mysql -u root -pkkk test mysql>show databases;mysql>use testmysql>show tables;#进入mysql以后用set来改密码. mysql> exit登录MySQL客户端控制台设置指定root密码 5. 编译安装PHP(FastCGI模式)tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
#解压并打补丁,让php支持fpm来方便管理php-cgi进程cd php-5.2.14/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/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/php/etc/php.ini
cd ../6.准备编译安装PHP5扩展模块tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
cd ../

tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../

tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../ 7. 修改php.ini文件,让php模块生效cp /lnmp/php-5.2.14/php.ini-dist /usr/local/php/etc/php.inivi php.iniextension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"

再查找output_buffering = Off修改为output_buffering = On

再查找; cgi.fix_pathinfo=0修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞 8. 在php.ini中配置eAccelerator加速PHPmkdir -p /usr/local/eaccelerator_cache#准备eaccelerator缓存目录 Vi php.ini[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
eaccelerator.enable="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"
eaccelerator.compress="1"
eaccelerator.compress_level="9" 9.准备php-cgi和nginx进程执行者用户Useradd nginx 10. 创建php-fpm配置文件- php-fpm.confvi /usr/local/php/etc/php-fpm.conf0#0改成1,页面上会输出错误日志Unix user of processes
nginx

Unix group of processes
nginx
128
#最大子进程数128,如果内存小于2G,则64个最佳65535
# Set open file desc rlimit,同时打开的文件数,linux系统允许同时打开的文件数为1024,修改linux系统中允许同时打开的文件,ulimit -SHn 65535,而且这个参数重启后还能生效,加到 /etc/profile全局配置文件的最后,开机就会生效,ulimit -a查看open files 655351024
#最大请求数, How much requests each process should execute before respawn.一个子进程能够回应1042个请求 11. 启动php-cgi(fastcgi)进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为nginx:/usr/local/php/sbin/php-fpm start#启动php-cgi/usr/local/php/sbin/php-fpm reload#重新加载配置文件/usr/local/php/sbin/php-fpm stop#关闭php-fpm,此时nginx肯定不上php 12. 安装Nginx所需的pcre库tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../ 13. 安装Nginxtar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../ 14. 修改Nginx配置文件vi /usr/local/nginx/conf/nginx.confuser nginx nginx;

worker_processes 8;#相当于cpu个数

error_log logs/nginx_error.log

pid /usr/local/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

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 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 65;

tcp_nodelay on;

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;

server
{
listen 80;
server_name blog.s135.com;
index index.html index.htm index.php;
root /data0/htdocs/blog;

#limit_conn crawler 20;

location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*.(js|css)?$
{
expires 1h;
}

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data1/logs/access.log access;
}
} 15. 在/usr/local/nginx/conf/目录中fastcgi_params文件添加fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 16.配置开机启动nginx,php-fpm,ulimit1)nginxVi /etc/rc.local/usr/local/nginx/sbin/nginx2)php-fpmVi /etc/rc.local/usr/local/php/sbin/php-fpm start3)ulimitVi /etc/profileUlimit -SHn 65535 17.检查nginx配置文件语句错误/usr/local/nginx/sbin/nginx -t 18.平滑重启nginx进程1)Pkill -HUP nginx2)kill -HUP `pgrep -uroot nginx`3)/usr/local/nginx/sbin/nginx -s reload (注意此处开启cgi /usr/local/php/sbin/php-fpm start)

20.配置nginx虚拟主机Vi /usr/local/nginx/conf/nginx.conf==èwww.baidu.com公司网站server
{
listen 80;
server_name www.baidu.com;
index index.html index.php index.htm;
root /web/baidu; location ~ .*.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
#设置图片在客户端缓存时间为30days
location ~ .*.(js|css)?$
{
expires 1h;
}
#设置js和css文件在客户端的缓存时间为1hour
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log logs/access.log access;#自定义日志区域
}
==èwww.sina.com公司网站 server
{
listen 80;
server_name www.sina.com;
index index.html index.php index.htm;
root /web/baidu; location ~ .*.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
#设置图片在客户端缓存时间为30days
location ~ .*.(js|css)?$
{
expires 1h;
}
#设置js和css文件在客户端的缓存时间为1hour
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log logs/access.log access;#自定义日志区域
}
最后在客户端测试虚拟主机www.baidu.com和www.sina.com两家公司网站

其他模块安装部分(环境不同 仅供参考) TTsevser (参考网址 http://www.cnblogs.com/kudosharry/articles/2261924.html)entos 5.5 下安装Tokyo 数据库tokyocabinet-1.4.47 和 网络接口tokyotyrant-1.1.41需求: 实现一个高性能类似memcached 内存缓存,并可以持续化数据。下载:wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.47.tar.gzwget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz 更新库:yum install bzip2-devel安装:tar -zxvf tokyocabinet-1.4.47.tar.gz && cd tokyocabinet-1.4.47 && ./configure --prefix=/home/tc && make && make installtar -zxvf tokyotyrant-1.1.41.tar.gz && cd tokyotyrant-1.1.41 && ./configure --prefix=/home/tt --with-tc=/home/tc && make && make install 软链接下库:ln -s /home/tc/lib/libtokyocabinet.so.9 /lib/libtokyocabinet.so.9启动:(mkdir /ttserver) cd /home/tt/bin/ ./ttserver 或: /home/tt/bin/ttserver -host 127.0.0.1 -port 1978 -thnum 8 -dmn -pid /ttserver/ttserver.pid -log /ttserver/ttserver.log -le -ulog /ttserver/ -ulim 128m -sid 1 -rts /ttserver/ttserver.rts /ttserver/database.tch 测试命令: 存储: curl -X PUT http://127.0.0.1:11211/my_key -d "this is value" 读取: curl http://127.0.0.1:11211/my_key 删除: curl -X DELETE http://127.0.0.1:11211/my_key 安装php扩展 tokyo_tyrantWebserver 相应目录--with-tokyo-tyrant 安装目录 相应改动wget http://pecl.php.net/get/tokyo_tyrant-0.6.0.tgz tar zxvf tokyo_tyrant-0.6.0.tgz
cd tokyo_tyrant-0.6.0
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-tokyo-tyrant=/usr/local/webserver/tt/ --with-tokyo-cabinet-dir=/usr/local/webserver/tc/
make
cd modules
cp tokyo_tyrant.so /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/
vi /usr/local/webserver/php/etc/php.ini
extension = tokyo_tyrant.so记得重启 Memcached /article/4895200.htmlhttp://blog.johntechinfo.com/technology/264
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: