標籤:
系統硬體:vmware vsphere (CPU:2*4核,記憶體2G)
系統版本:CentOS Linux release 7.0.1406
安裝步驟:
1.系統內容
1.1 更新系統
[[email protected] ~]# yum update -y
1.2 查看環境
[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
[[email protected] ~]# uname -a
Linux tengine 3.10.0-123.4.2.el7.x86_64 #1 SMP Mon Jun 30 16:09:14 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
2.安裝tengine
2.1.準備安裝
[[email protected] ~]# cd /usr/local/src/
下載 pcre-8.35.tar.gz到/usr/local/src
[[email protected] ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
下載zlib-1.2.8.tar.gz到/usr/local/src
[[email protected] ~]# wget http://zlib.net/zlib-1.2.8.tar.gz
下載 openssl-1.0.1h.tar.gz到/usr/local/src
[[email protected] ~]# wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
下載jemalloc-3.6.0.tar.bz2到/usr/local/src
[[email protected] ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
下載 tengine-2.0.3.tar.gz到/usr/local/src
[[email protected] ~]# wget http://tengine.taobao.org/download/tengine-2.0.3.tar.gz
2.2 更新包
[[email protected] ~]# yum install zlib-devel openssl-devel -y
2.3 安裝Pcre
[[email protected] ~]# cd /usr/local/src/
[[email protected] ~]# tar zvxf pcre-8.35.tar.gz
[[email protected] ~]# cd pcre-8.35
[[email protected] ~]# ./configure
[[email protected] ~]# make && make install
2.4 安裝openssl
[[email protected] ~]# cd /usr/local/src/
[[email protected] ~]# tar zvxf openssl-1.0.1h.tar.gz
[[email protected] ~]# cd openssl-1.0.1h
[[email protected] ~]# ./config
[[email protected] ~]# make && make install
2.5 安裝zlib
[[email protected] ~]# cd /usr/local/src/
[[email protected] ~]# tar zlib-1.2.8.tar.gz
[[email protected] ~]# cd zlib-1.2.8
[[email protected] ~]# ./configure
[[email protected] ~]# make && make install
2.6 安裝jemalloc
[[email protected] ~]# cd /usr/local/src/
[[email protected] ~]# tar zvxf jemalloc-3.6.0
[[email protected] ~]# cd jemalloc-3.6.0
[[email protected] ~]# ./configure
[[email protected] ~]# make && make install
[[email protected] ~]# echo ‘/usr/local/lib‘ > /etc/ld.so.conf.d/local.conf
[[email protected] ~]# ldconfig
4.4 建立www使用者和組,建立www虛擬機器主機使用的目錄,以及Nginx使用的日誌目錄,並且賦予他們適當的許可權
[[email protected] ~]# groupadd www
[[email protected] ~]# useradd -g www www
[[email protected] ~]# mkdir -p /data/www
[[email protected] ~]# chmod +w /data/www
[[email protected] ~]# chown -R www:www /data/www
4.5 安裝tengine
[[email protected] ~]# cd /usr/local/src/
[[email protected] ~]# tar zvxf tengine-2.0.3.tar.gz
偽裝伺服器資訊(可以不修改)
[[email protected] ~]# cd nginx-1.6.0/src/core
[[email protected] ~]# vim ./src/core/nginx.h
修改NGINX_VERSION為你希望顯示的版號
修改NGINX_VER為你希望顯示的名稱
修改NGINX_VAR 為你希望顯示的名稱
儲存
開始安裝NGINX
./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35 --with-jemalloc
[[email protected] ~]# make && make install
4.6 修改 nginx.conf
[[email protected] ~]# vim /opt/nginx/conf/nginx.conf
修改前面幾行為:
user www www;
worker_processes 4;
error_log logs/error.log crit;
pid logs/nginx.pid;
events{
use epoll;
worker_connections 65535;
}
4.7 測試和運行
[[email protected] ~]# cd /opt/nginx
[[email protected] ~]# ldconfig
[[email protected] ~]# ./sbin/nginx -t
如果顯示下面資訊,即表示配置沒問題
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
輸入代碼運行nginx服務
[[email protected] ~]# ./sbin/nginx
[[email protected] ~]# ps au|grep nginx
如果顯以類似下面的資訊,即表示nginx已經啟動
root 2013 0.0 0.0 103156 856 pts/0 S+ 03:22 0:00 grep nginx
輸入代碼檢測是否支援加速
查看是否生效
[[email protected] ~]# lsof -n | grep jemalloc
ginx 2346 root mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2347 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2348 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2349 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2350 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
[[email protected] ~]# curl http://localhost
4.8 開啟防火牆80連接埠
#停止firewall
[[email protected] ~]# systemctl stop firewalld.service
#禁止firewall開機啟動
[[email protected] ~]# systemctl disable firewalld.service
安裝 iptables
[[email protected] ~]# yum install iptables-services
設定防火牆規則 (增加80連接埠)
[[email protected] ~]# vim /etc/sysconfig/iptables
開啟檔案,增加80連接埠那一行
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq #儲存退出
#重啟防火牆使配置生效
[[email protected] ~]# systemctl restart iptables.service
#設定防火牆開機啟動
[[email protected] ~]# systemctl enable iptables.service
4.9 作為服務,開機後啟動
[[email protected] ~]# vim /usr/lib/systemd/system/tengine.service
增加以下內容
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
:wq 儲存退出
[[email protected] ~]# systemctl stop tengine
[[email protected] ~]# systemctl start tengine
[[email protected] ~]# systemctl reload tengine
[[email protected] ~]# systemctl enable tengine
[[email protected] ~]# shutdown -r now
編譯安裝 Centos 7 x64 + tengine.2.0.3 (實測+筆記)