nginx編譯安裝

系統環境配置:

**  配置阿里雲的yum 源

**  配置perl yum 擴展源

rpm -ivh  epel-realease.xxxx

yum makecache

1.首先安裝必要的依賴,GeoIP ,yum 不能裝的話,需要eperl 源,(使用阿里源,不要使用163源,容易出問題)

yum install gcc pcre pcre-devel openssl openssl-devel GeoIP-devel perl-ExtUtils-Embed gd gd-devel libxml2* libxslt*

2.建好nginx 用戶 和指定的目錄,防止後面啓動nginx 找到不到文件

useradd -M -s /nologin nginx

mkdir -p /var/lib/nginx/tmp

3.爲了使用goole 開發的開源工具優化nginx 內存(內存的使用和分配)的TCMalloc  ,需要提前提前安裝 libunwind  和gperltools 這兩個安裝包

a.安裝libunwind(32位不需要安裝,64位需要安裝)

tar -xf  libxxxx.tar.gz

cd libxxxx

./configure prefix=/usr

make && make install

b.安裝gpertools

tar -xf gperftools.tar.gz

cd gperftools

./configure --enable-frame-pointers (64位的要啓用框架指針,否則後面會報錯

make && make install

c.增加gperftools 的線程目錄

mkdir /tmp/tcmalloc

chmod 777 /tmp/tcmalloc

d.加載到系統標準庫文件

echo "/usr/local/lib" >>/etc/ld.so.conf

ldconfig  #使之生效

4.編譯安裝nginx,編譯選項如下:如果直接黏貼到終端,可能會有編碼問題, 最好使用dos2unix 轉換下

./configure \

--prefix=/usr/local/nginx \

--sbin-path=/usr/sbin/nginx \

--error-log-path=/var/log/nginx/error.log \

--pid-path=/var/run/nginx.pid \

--lock-path=/var/lock/subsys/nginx \

--user=nginx \

--with-http_ssl_module \

--with-http_v2_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_xslt_module \

--with-http_p_w_picpath_filter_module \

--with-http_geoip_module \

--with-http_dav_module \

--with-http_flv_module \

--with-http_mp4_module  \

--with-http_gunzip_module \

--with-http_gzip_static_module \

--with-http_random_index_module \

--with-http_secure_link_module  \

--with-http_degradation_module \

--with-http_stub_status_module \

--with-http_perl_module \

--http-client-body-temp-path=/var/lib/nginx/tmp/client-body \

--http-proxy-temp-path=/var/lib/nginx/tmp/proxy \

--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \

--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \

--http-scgi-temp-path=/var/lib/nginx/tmp/scgi \

--with-google_perftools_module \

--with-pcre \

--with-debug \

--with-file-aio

make && make install

5.修改配置文件

vim  /path/to/nginx.conf

在pid 下面添加如下內容:

google_perftools_profiles /tmp/tcmalloc;

6,保存啓動nginx ,查看是否正常,查看進程:

lsof -n |grep tcmalloc


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章