[LTMP架构]ubuntu系统安装tengine+mysql+redis+phpmyadmin

1.安装Linux系统常用个工具

sudo apt install -y vim git curl wget htop coreutils build-essential net-tools openssh-client openssh-server zip unzip tree

2.下载tengine(nginx)软件

wget https://tengine.taobao.org/download/tengine-3.1.0.tar.gz

3.cd到文件下载目录,执行如下命令,解压数据包

tar -zxvf tengine-3.1.0.tar.gz

4.cd到解压的数据包文件夹内,依赖工具安装

sudo apt install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev

5.安装完成之后,执行如下命令

./configure --prefix=/opt/tengine/ --with-stream \
            --with-http_ssl_module \
            --with-http_gzip_static_module \
            --with-http_stub_status_module

6.执行编译安装

make -j
sudo make install

7.添加到PATH环境变量

vim /etc/profile

在文件末尾添加

export PATH=$PATH:/opt/tengine/sbin/

  然后执行:wq!保存退出

8.加载文件到当前的bash环境中

source /etc/profile

9.执行nginx命令 启动nginx,输入下方命令查看nginx是否运行或已启动

ps aux|grep nginx

10.运行如下命令 修改nginx配置文件

vim /opt/tengine/conf/nginx.conf

打开后将内容全部清空,换成如下优化内容

user nginx;
worker_processes auto;
error_log /opt/tengine/logs/error.log info;
error_log "pipe:rollback logs/error_log interval=1d backnum=7 maxsize=2G";
pid       /opt/tengine/run/nginx.pid;
events {
  worker_connections 10240;
  use epoll;
  accept_mutex on;
}

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"';
  log_format access_json '{"@timestamp":"$time_iso8601",'
  			 '"host":"$server_addr",'
  			 '"clientip":"$remote_addr",'
  			 '"size":$body_bytes_sent,'
  			 '"responsetime":$request_time,'
  			 '"upstreamtime":"$upstream_response_time",'
  			 '"upstreamhost":"$upstream_addr",'
  			 '"http_host":"shost",'
  			 '"uri":"$uri",'
  			 '"domain":"$host",'
  			 '"protocol":"$scheme",'
  			 '"xff":"$http_referer",'
  			 '"tcp_xff":"$proxy_protocol_addr",'
  			 '"http_user_agent":"$http_user_agent",'
  			 '"status":"$status"}'; 
  access_log   /opt/tengine/logs/access_json.log  access_json;
  sendfile     on;
  keepalive_timeout   65;
  keepalive_requests   200;
  client_max_body_size  10m;
  proxy_cache_path  /opt/tengine/conf/proxy_cache  levels=1:2:2  keys_zone=proxycache:20m inactive=120s max_size=1g;
  fastcgi_cache_path  /opt/tengine/conf/php_cache  levels=1:2:2  keys_zone=phpcache:20m inactive=120s max_size=1g;
  gzip    on;
  gzip_comp_level 5;
  gzip_min_length 1k;
  gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
  gzip_vary on;
  open_file_cache max=20000 inactive=60s;
  open_file_cache_valid 60s;
  open_file_cache_min_uses 5;
  open_file_cache_errors on;
  server_tokens off;
  include /opt/tengine/conf/http/*.conf;
  include /opt/tengine/conf/tcp/*.conf;
}

更换完成之后,在终端输入输入以下命令,创建相关文件目录(七层代理相关配置文件夹)

mkdir -p /opt/tengine/{conf,logs,run}
mkdir -p /opt/tengine/conf/{http,tcp}

  (nginx优化)   给nginx添加用户名

sudo adduser --system --no-create-home --disabled-login --group nginx

执行nginx重新载入命令

nginx -s reload

执行cat命令查看nginx的pid是否为空

cat  /opt/tengine/run/nginx.pid

如果执行上述命令后 终端内未显示pid进程,则执行如下命令

pkill /opt/tengine/run/nginx.pid

#再执行!ps 查看是否有pid进程

------------------PHP安装--------------

1.安装PHP相关文件

apt install php php-cli php-redis php-fpm php-json php-mysql php-zip php-gd php-mbstring php-curl php-xml php-bcmath -y

2.优化 /etc/php/8.1/fpm/pool.d/www.conf

执行如下命令 并清空www.conf内容

vim /etc/php/8.1/fpm/pool.d/www.conf

将下列内容保存至www.conf

[WWW]

user = nginx
group = nginx
listen = /run/php/php8.1-fpm.sock
listen.acl_users = nginx
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = redis
php_value[session.save_path] = "tcp://127.0.0.1:6379"
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
ping.path = /ping
ping.response = ping-pong
pm.status_path = /pm_status

3.新建php.conf文件到conf目录(七层代理配置文件夹),内容如下(反向代理)

server{
  listen 80;
  server_name www.[你的域名].com;
  location / {
     root /data/php/;
     index index.php index.html index.htm;
  }
  
  location ~ \.php$ {
      root               /data/php/;
      fastcgi_pass       unix:///run/php/php8.1-fpm.sock;
      fastcgi_index      index.php;
      fastcgi_param      SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include            fastcgi_params;
      fastcgi_keep_conn  on;
      fastcgi_pass_header Status;
      
      fastcgi_cache  phpcache;
      fastcgi_cache_key $request_uri;
      fastcgi_cache_valid 200 302 301 10m;
      fastcgi_cache_valid any 2m;
  }
}

未完待续.....


  
  
  
  
  
  
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值