Tengine详细安装教程,
Tengine详细安装教程,
环境:
系统硬件:VMware Workstation 10 (CPU:2*4核,内存512M)
系统版本:CentOS linux release 6.8
安装步骤:
1.系统环境
1.1 更新系统
[root@centos ~]# yum update -y
[root@centos ~]# yum install gcc gcc-c++ autoconf automake (安装pcre时需要)
1.2 查看环境
[root@centos ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@centos ~]# uname -a
Linux sxc1 2.6.32-642.13.1.el6.x86_64 #1 SMP Wed Jan 11 20:56:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
2.安装tengine
2.1.准备安装
[root@centos ~]# cd /usr/local/src/
(1)下载 pcre-8.35.tar.gz到/usr/local/src
说明:PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx rewrite依赖于PCRE库,所以在安装Tengine前一定要先安装PCRE,最新版本的PCRE可在官网(http://www.pcre.org/)获取
[root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
(2)下载zlib-1.2.11.tar.gz到/usr/local/src
说明:Zlib是提供资料压缩之用的函式库,当Tengine想启用GZIP压缩的时候就需要使用到Zlib(http://www.zlib.net/)
[root@centos ~]# wget http://www.zlib.net/zlib-1.2.11.tar.gz
(3)下载 openssl-1.0.1h.tar.gz到/usr/local/src
说明:OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。,安装OpenSSL(http://www.openssl.org/source/)主要是为了让tengine支持Https的访问请求
[root@centos ~]# wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
(4)下载jemalloc-3.6.0.tar.bz2到/usr/local/src
说明:jemalloc(http://www.canonware.com/jemalloc/)是一个更好的内存管理工具,使用jemalloc可以更好的优化Tengine的内存管理
[root@centos ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
(5)下载 tengine-2.2.0.tar.gz到/usr/local/src
[root@centos ~]# wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz
2.2 更新包
[root@centos ~]# yum install zlib-devel openssl-devel -y
2.3 安装Pcre
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zvxf pcre-8.35.tar.gz
[root@centos ~]# cd pcre-8.35
[root@centos ~]# ./configure
[root@centos ~]# make && make install
2.4 安装openssl
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zvxf openssl-1.0.1h.tar.gz
[root@centos ~]# cd openssl-1.0.1h
[root@centos ~]# ./config
[root@centos ~]# make && make install
2.5 安装zlib
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zlib-1.2.11.tar.gz
[root@centos ~]# cd zlib-1.2.11
[root@centos ~]# ./configure
[root@centos ~]# make && make install
2.6 安装jemalloc
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zvxf jemalloc-3.6.0
[root@centos ~]# cd jemalloc-3.6.0
[root@centos ~]# ./configure
[root@centos ~]# make && make install
[root@centos ~]# echo ‘/usr/local/lib‘ > /etc/ld.so.conf.d/local.conf
[root@centos ~]# ldconfig
4.4 创建sxc用户和组g_sxc,创建sxc虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限
[root@centos ~]# groupadd g_sxc
[root@centos ~]# useradd -g g_sxc sxc
[root@centos ~]# mkdir -p /data/sxc
[root@centos ~]# chmod +w /data/sxc
[root@centos ~]# chown -R sxc:g_sxc /data/sxc
4.5 安装tengine
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar -zvxf tengine-2.2.0.tar.gz
开始安装NGINX
./configure --prefix=/home/sxc/nginx --user=sxc --group=g_sxc --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.11 --with-pcre=/usr/local/src/pcre-8.35 --with-jemalloc
[root@centos ~]# make && make install
4.6 修改 nginx.conf
[root@centos ~]# vim /home/sxc/nginx/conf/nginx.conf
修改前面几行为:
user sxc g_sxc;
worker_processes 2;
error_log logs/error.log;
pid logs/nginx.pid;
events{
use epoll;
worker_connections 65535;
}
4.7 测试和运行
[root@centos ~]# cd /home/sxc/nginx
[root@centos ~]# ldconfig
[root@centos ~]# ./sbin/nginx -t
如果显示下面信息,即表示配置没问题
nginx: the configuration file /home/sxc/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /home/sxc/nginx/conf/nginx.conf test is successful
输入代码运行nginx服务
[root@centos ~]# ./sbin/nginx
[root@centos ~]# ps au|grep nginx
如果显以类似下面的信息,即表示nginx已经启动
root 2924 0.0 0.1 103312 864 pts/1 S+ 01:14 0:00 grep nginx
输入代码检测是否支持加速
查看是否生效
[root@centos ~]# lsof -n | grep jemalloc
nginx 2387 root mem REG 8,2 5031635 1335420 /usr/local/lib/libjemalloc.so.1
nginx 2393 sxc mem REG 8,2 5031635 1335420 /usr/local/lib/libjemalloc.so.1
nginx 2394 sxc mem REG 8,2 5031635 1335420 /usr/local/lib/libjemalloc.so.1
[root@centos ~]# curl http://localhost
4.8 打开防火墙80端口
安装 iptables(已安装可忽略)
[root@centos ~]# yum install iptables-services
设置防火墙规则 (增加80端口)
[root@centos ~]# 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 #保存退出
#重启防火墙使配置生效
[root@centos ~]# service iptables restart
#设置防火墙开机启动
[root@centos ~]# chkconfig iptables on
4.9 作为服务,开机后启动
在/etc/init.d/下创建nginx文件
[root@centos ~]# vim /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/home/sxc/nginx/sbin/nginx
nginx_config=/home/sxc/nginx/conf/nginx.conf
nginx_pid=/home/sxc/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
修改属性与实际环境一致
nginxd=/home/sxc/nginx/sbin/nginx
nginx_config=/home/sxc/nginx/conf/nginx.conf
nginx_pid=/home/sxc/nginx/logs/nginx.pid
设置所有用户可执行
chmod a+x /etc/init.d/nginx
可以启动停止
/etc/init.d/nginx start
/etc/init.d/nginx stop
加入chkconfig管理列表
chkconfig --add /etc/init.d/nginx
使用service进行管理
service nginx start
service nginx stop
设置开机自启动
chkconfig nginx on
评论暂时关闭