Tengine 详细安装与配置

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: Tengine和nginx差不多,方便实用

1.节点初始化

yum -y install nfs-utils portmap rpcbind vim crontab chkconfig \
initscripts gcc-c++ libstdc++-devel zlib zlib-devel glib glib-devel \
libxml2 libxml2-devel make bzip2-devel pcre pcre-devel libjpeg libjpeg-devel \
libpng libpng-devel freetype freetype-devel gmp gmp-devel unixODBC \
unixODBC-devel gcc g++ make autoconf automake libxml2 libxml2-devel vsftpd \
pcre pcre-devel iptraf aspell aspell-devel screen hwinfo hdparm varnishd memcached

2.安装需要的包

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-servers pcre-devel libxslt \
libxslt-devel libtool-ltdl libtool-ltdl-devel

3.安装Tengine

wget http://tengine.taobao.org/download/tengine-1.5.1.tar.gz
tar xzf tengine*.tar.gz
cd tengine-*
./configure --prefix=/usr/local/nginx --with-http_concat_module \
--with-http_addition_module --with-http_dav_module \
--with-http_gzip_static_module --with-http_image_filter_module \
--with-http_realip_module --with-http_stub_status_module \
--with-http_ssl_module --with-http_sub_module --with-ipv6 \
--with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl \
--with-mail --with-mail_ssl_module
make && make install

4.配置Tengine

vim /usr/local/nginx/conf/nginx.conf

user apache apache;

worker_processes auto;

worker_cpu_affinity auto;

worker_rlimit_nofile 65535;

error_log logs/error.log crit;

pid /var/run/nginx.pid;

events {

    use epoll;

    worker_connections  65535;

}

dso {

load ngx_http_upstream_session_sticky_module.so;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    log_format  main  '$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  main;

    sendfile        on;

    tcp_nopush      on;

    tcp_nodelay on;

    keepalive_timeout  65;

fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m;

    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;

fastcgi_cache TEST;

    fastcgi_cache_valid 200 302 1h;

    fastcgi_cache_valid 301 1d;

    fastcgi_cache_valid any 1m;

    fastcgi_cache_min_uses 1;

    fastcgi_cache_use_stale error timeout invalid_header http_500;

    large_client_header_buffers 4 4k;

    server_names_hash_bucket_size 128;

    client_max_body_size 8m;

    client_header_buffer_size 4k;

    open_file_cache max=65535 inactive=20s;

    open_file_cache_valid 30s;

    open_file_cache_min_uses 1;

    gzip    on;

    gzip_min_length 1k;

    gzip_buffers 4 16k;

    gzip_http_version       1.1;

    gzip_comp_level 2;

    gzip_types      text/plain application/x-javascript text/css application/xml;

    gzip_vary on;

server {

            listen       80;

            server_name  192.168.0.178;

server_name www.mreald.com www.www.mreald.com;

            root   /disk1/www.mreald.com/;

            location / {

                    index  index.php index.html index.htm;

                    if (!-f $request_filename) {

                            rewrite ^/(.*)$ /index.php/$1 last;

                    }

            }

            location ~ \.php($|/) {

                    fastcgi_pass 127.0.0.1:9000;

                    fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

                    include       fastcgi_params;

                    include       fastcgi.conf;

            }

            error_page   500 502 503 504  /50x.html;

            location = /50x.html {

                    root   html;

            }

    }

    server {

            listen 443;

            server_name  192.168.0.178;

server_name www.mreald.com www.www.mreald.com;

            ssl on;

            ssl_certificate /usr/local/nginx/conf/ssl/server.crt;

            ssl_certificate_key /usr/local/nginx/conf/ssl/server.key;

            root   /disk1/www.mreald.com/;

            location / {

                    index  index.php index.html index.htm;

                    if (!-f $request_filename) {

                            rewrite ^/(.*)$ /index.php/$1 last;

                    }

            }

            location ~ \.php($|/) {

                    fastcgi_pass 127.0.0.1:9000;

                    fastcgi_index index.php;

                    include fastcgi_params;

                    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

                    include       fastcgi_params;

            }

            error_page   500 502 503 504  /50x.html;

            location = /50x.html {

                    root   html;

            }

    }

}

5 编译安装php

wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
tar xzf libmcrypt-2.5.8.tar.gz
cd libmcrypt-*
./configure 
make && make install
yum install mysql mysql-server
cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so


wget http://cn2.php.net/get/php-5.3.25.tar.gz/from/us1.php.net/mirror
 tar xzf php-5*.tar.gz
cd php-5*
  ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-iconv \
  --with-zlib --enable-xml --disable-rpath   --enable-safe-mode --enable-bcmath --enable-shmop \
  --enable-sysvsem --enable-inline-optimization   --with-curl --with-curlwrappers --enable-mbregex \
  --enable-mbstring --with-mcrypt --with-gd   --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl \
  --enable-sockets  --with-xmlrpc   --enable-zip --enable-soap --without-pear --with-mysql --with-mysqli \
  --enable-sqlite-utf8 --with-pdo-mysql   --enable-ftp --with-jpeg-dir --with-freetype-dir --with-png-dir \
  --enable-fpm --with-fpm-user=apache   --with-fpm-group=apache      --enable-pcntl  \
  --with-config-file-scan-dir=/usr/local/php/etc/   --enable-exif --with-gettext --disable-wddx \
  --with-xsl
make -j7 && make install


vim   /usr/local/php/etc/php-fpm.conf

[global]

[www]

user = apache

group = apache

listen = 127.0.0.1:9000

pm = dynamic

pm.max_children = 200

pm.start_servers = 2

pm.min_spare_servers = 1

pm.max_spare_servers = 3

pm.max_requests = 500

rlimit_files = 65535

启动fpm进程(/usr/local/php/etc/php.ini)---session.save_path /var/lib/php/nginx-session

chown

cp /etc/php.ini.rpmsave /etc/php.ini
cp /etc/php-fpm.d/www.conf.rpmsave /etc/php-fpm.d/www.conf
/usr/local/php/sbin/php-fpm -c /etc/php.ini
6.重启php-fpm nginx

kill -USR2 cat /usr/local/php/var/run/php-fpm.pid
ps aux|grep fpm|awk '{print $2}'|xargs kill
ps aux|grep nginx|awk '{print $2}'|xargs kill;/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm -c /etc/php.ini
ps aux|grep process|awk '{print $2}'|xargs kill;/usr/local/nginx/sbin/nginx;
ps aux|grep fpm|awk '{print $2}'|xargs kill;
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
7.设置打开最大文件数

ulimit

vim /etc/rc.local

ulimit -SHn 65535

vim /etc/profile

ulimit -SHn 65535

source /etc/profile

vim /etc/security/limits.conf

  • soft nofile 65535
  • hard nofile 65535
  • soft nproc 65535
  • hard nproc 65535

/usr/local/nginx/sbin/nginx -s reload

ulimit -a /-n

8.内核参数优化:

vim /etc/sysctl.conf

net.ipv4.ip_forward = 0

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

kernel.sysrq = 0

kernel.core_uses_pid = 1

net.ipv4.tcp_syncookies = 1

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 68719476736

kernel.shmall = 4294967296

net.ipv4.tcp_max_tw_buckets = 6000

net.ipv4.tcp_sack = 1

net.ipv4.tcp_window_scaling = 1

net.ipv4.tcp_rmem = 4096 87380 4194304

net.ipv4.tcp_wmem = 4096 16384 4194304

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.core.netdev_max_backlog = 262144

net.core.somaxconn = 262144

net.ipv4.tcp_max_orphans = 3276800

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 1

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.ipv4.tcp_fin_timeout = 1

net.ipv4.tcp_keepalive_time = 30

net.ipv4.ip_local_port_range = 1024 65000

sysctl -p

9.写一个启动脚本:

vim /etc/init.d/nginx

!/bin/sh

nginx - this script start and stop the nginx daemon

chkconfig: 2345 55 25

description: Startup script for nginx

processname: nginx

config: /usr/local/nginx/conf/nginx.conf

pidfile: /var/run/nginx.pid

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DAEMON=/usr/local/nginx/sbin/nginx

CONFIGFILE=/usr/local/nginx/conf/nginx.conf

PIDFILE=/var/run/nginx.pid

SCRIPTNAME=/etc/init.d/nginx

LOCKFILE=/var/lock/nginx.lock

set -e

[ -x "$DAEMON" ] || exit 0

start() {

   echo "Startting Nginx......"

   [ -x $DAEMON ] || exit 5

   [ -f $CONFIGFILE ] || exit 6

   $DAEMON -c $CONFIGFILE || echo -n "Nginx already running!"

   [ $? -eq 0 ] && touch $LOCKFILE

}

stop() {

   echo "Stopping Nginx......"

   MPID=`ps aux | grep nginx | awk '/master/{print $2}'`

   if [ "${MPID}X" != "X" ]; then

           kill -QUIT $MPID

           [ $? -eq 0 ] && rm -f $LOCKFILE

   else

           echo "Nginx server is not running!"

   fi

}

reload() {

   echo "Reloading Nginx......"

   MPID=`ps aux | grep nginx | awk '/master/{print $2}'`

   if [ "${MPID}X" != "X" ]; then

           kill -HUP $MPID

   else

           echo "Nginx can't reload!"

   fi

}

case "$1" in

start)

   start

   ;;

stop)

   stop

   ;;

reload)

   reload

   ;;

restart)

   stop

   sleep 1

   start

   ;;

*)

   echo "Usage: $SCRIPTNAME {start|stop|reload|restart}"

   exit 3

   ;;

esac

exit 0

chmod +x /etc/init.d/nginx
chkconfig --add nginx
service nginx start

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
tengine 关系型数据库 MySQL
Tengine、Nginx安装MySQL数据库命令教程
本指南详细介绍了在Linux系统上安装与配置MySQL数据库的步骤。首先通过下载并安装MySQL社区版本,接着启动MySQL服务,使用`systemctl start mysqld.service`命令。若启动失败,可尝试使用`sudo /etc/init.d/mysqld start`。利用`systemctl status mysqld.service`检查MySQL的服务状态,确保其处于运行中。通过日志文件获取初始密码,使用该密码登录数据库,并按要求更改初始密码以增强安全性。随后创建一个名为`tengine`的数据库,最后验证数据库创建是否成功以及完成整个设置流程。
|
2月前
|
tengine 应用服务中间件 Linux
Tengine、Nginx安装PHP命令教程
要在阿里云Linux上安装PHP,请先更新YUM源并启用PHP 8.0仓库,然后安装PHP及相关扩展。通过`php -v`命令验证安装成功后,需修改Nginx配置文件以支持PHP,并重启服务。最后,创建`phpinfo.php`文件测试安装是否成功。对于CentOS系统,还需安装EPEL源和Remi仓库,其余步骤类似。完成上述操作后,可通过浏览器访问`http://IP地址/phpinfo.php`测试安装结果。
|
2月前
|
tengine 应用服务中间件 nginx
Tengine命令安装教程
该内容提供了一套详细的步骤指南,用于通过 FinalShell 远程连接并安装 Tengine 服务器。从下载与配置 Tengine,到使用 yum 安装必要的组件,再到编译、安装及配置 Nginx,以及如何处理 HTTPS 部署和证书设置,最后涵盖了基本的站点程序控制命令。此外,还提供了隐藏版本号的方法及文本编辑技巧。
|
6月前
|
tengine Linux 应用服务中间件
CentOS 7 安装 Tengine
CentOS 7 安装 Tengine
|
tengine 应用服务中间件 Linux
【Linux环境】如何在Nginx(或Tengine)服务器上安装ssl证书----介绍nginx服务器类型证书的下载与安装操作
【Linux环境】如何在Nginx(或Tengine)服务器上安装ssl证书----介绍nginx服务器类型证书的下载与安装操作
517 0
|
tengine 应用服务中间件 nginx
|
应用服务中间件 nginx tengine
|
tengine 应用服务中间件 Linux
|
tengine Shell 应用服务中间件