1.备份虚拟机tenginevir(ubuntu12.04),一个好习惯
2.安装tengine-1.5.0
先给张安装成功后的图,输入一个不存在的URL,结果:
开始安装,基本步骤:
1、下载软件包:
wget http://tengine.taobao.org/download
2、安装pcre,如果已经安装yum服务,请直接使用:yum install pcre,
否则请去官方下载安装如下:
cd /usr/local/src
tar zxvf pcre-8.33.tar.gz
mkdir /usr/local/pcre #创建安装目录
cd pcre-8.33
./configure --prefix=/usr/local/pcre #配置
Make
make install
3、安装 nginx
cd /usr/local/src
tar zxvf tengine-1.5.0.tar.gz
cd tengine-1.5.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_concat_module --with-openssl=/usr/local/openssl/openssl-1.0.1c --with-pcre=/usr/local/src/pcre-8.33
openssl是我自己安装的,路径可能和其他人的不一样
make
make install
4、启动nginx
/usr/local/nginx/sbin/nginx
chown nobody.nobody -R /usr/local/nginx/html
chmod 700 -R /usr/local/nginx/html
5.脚本启动
vi /etc//init.d/nginx #编辑启动文件
#!/bin/bash
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Check that networking is up.
#xubangjiang,20130802,1326712915@qq.com
[ [${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 /usr/local/nginx/logs/nginx.pid
}
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
__________________________________________________________
:wq!保存退出
chmod 775 /etc/init.d/nginx #赋予文件执行权限
chkconfig nginx on #设置开机启动
/etc/init.d/nginx restart
service nginx restart
遇到的问题:
问题1:
make失败,提示:error:you need a c++ compiler for c++ support
解决方法:网上说yum -y install gcc就可以了,试了一下,然后发觉yum没有安装,安装一下。 apt-get install yum
结果获得了下面的提示:
error: Unable to locate package yum
说明找不到yum的安装源,所以apt
apt-get update
更新一下安装源,再次安装:
apt-get install yum
成功,然后再来安装gcc
yum -y install gcc gcc-c++
失败,Google一下发现用下面的命令:
apt-get install g++
终于安装完成,再次configure.
问题2:缺少zlib库文件
到ChinaUnix下载zlib-1.2.7.tar.gz软件
新建一个安装目录,拷贝至该目录
tar xvzf zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure
make
make install
注意权限,必要时用sudo完成
问题3:
prefix=/usr/local/nginx该目录需要自己建立
问题4:
openssl需要在ChinaUnix上去下载1.0.1c.tar.gz版本,自己手动安装,否则安装tengine的时候 检测依赖关系会报错,
注意这次用的是./config,openssl是一个安全的套接字层加密工具,支持多个软件和工具。我的linux是12.04的,刚装,很多东西都没有。
问题5:
517:32 error:tengine variable 'clcf' set but not used,打开所在文件,把涉及该变量的两行 注释掉,然后make、make install就ok了
问题6:nobody.nobody不存在这个用户:用户组,替代为bang.bang,本机上有的用户名
问题6:为了设置开机自启动,有可能需要apt-get install chkconfig
问题7:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
问题描述:地址已被使用。可能nginx服务卡死了,导致端口占用,出现此错误。
解决方法:首先用lsof -i:80看下80端口被什么程序占用。lsof返回结果如下:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 3244 root 6u IPv4 10664 0t0 TCP *:http (LISTEN)
nginx 3245 nginx 6u IPv4 10664 0t0 TCP *:http (LISTEN)
发现是nginx程序已经在运行,自己占用了端口。所以我们把nginx服务k掉,重新启动服务。。命令如 下:
kill -9 3244
kill -9 3545
service nginx start
Starting nginx: [ OK ]
问题8:访问页面时出现的403(permission denied)错误
这种方法有点暴力,不过换成其他数字都不行,数字(根、属主、属组的二进制),不知道是不是前面哪里出错了
chmod 777 -R /usr/local/nginx/html
问题9:在/usr/local/nginx/sbin/nginx处可以启动nginx(确切地说是tengine),但是不能从脚本启动
即输入service nginx start时提示service unrecognized,这是因为启动脚本必须要放在/etc/init.d目录下,linux(ubuntu2.04)才能检测到这是一个服务的脚本,我看了该目录下有很多脚本,比如bluetooth之类的。然后脚本里有两行路径的信息不正确,每次都会提示,但不影响操作。可以在脚本里注释掉。
我是小白,好多东西不懂,不懂就google、度娘;系统也是小白,好多东西没有,没有就apt、install,所以这是两个小白的故事。
本文原创,转载请注明出处。