首页 » LNMP » LNMP一键安装,yum安装

LNMP一键安装,yum安装

 

一、nginx的yum安装:

1、安装epel源,可以直接安装 ,查看安装的nginx的相关信息:yum info nginx

2、用官方的yum源。如果安装最新的stable version,在/etc/yum.repos.d/下面增加,nginx.repo文件内容如下:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

如果安装最新的mainline version,nginx.repo的内容如下:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

官方说明:http://nginx.org/en/linux_packages.html#stable

nginx.conf:

user  nginx;
worker_processes  4;
worker_cpu_affinity 00000001 00000010 00000100 00001000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 65535;


events {
    use epoll;
    worker_connections  1024;
}


http {
    server_tokens off;
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    charset	utf-8;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 64k;
    client_max_body_size 8m;
    sendfile on;
    tcp_nopush     on;
    tcp_nodelay on;
    keepalive_timeout 60;
    fastcgi_intercept_errors on;
    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;
    
    open_file_cache max=65535 inactive=10s;
    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.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/javascript text/css application/xml  text/xml image/jpeg ;
    gzip_vary on;
    

    include /etc/nginx/conf.d/*.conf;
}

 

如果需要用tcp反向代理的话,需要安装stream模块,yum安装的会自动安装,如果编译的话,需要加上参数如下–with-stream ,最好是把它相关的加上,万一要用呢。

--with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module

安装完之后,需要使用tcp四层代理的话,如果是nginx-1.10.1的版本,需要加载modules配置,如下:include /usr/share/nginx/modules/*.conf;

如果是最新稳定版本nginx_1.12.1的话,是不需要的。如果报stream指令不在的话,那就说明stream模块没有加载或安装。

 

案例:

include /usr/share/nginx/modules/*.conf;
stream {
        server {
        listen 8000;
        proxy_pass 192.168.7.206:4000;
}
}

可以参考官方:https://www.nginx.com/resources/admin-guide/tcp-load-balancing/

二、mysql安装,

 

http://dev.mysql.com/downloads/repo/yum/

http://dev.mysql.com/doc/refman/5.7/en/

以上是官网下载yum源,下载只下载了一个rpm包,但里面有5.5,5.6,5.7三个版本安装,如果只想安装5.6,可以参考官方:

http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

http://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

安装最新的版本:yum install mysql-community-server -y

安装其他版本 :

yum-config-manager –disable mysql57-community
yum-config-manager –enable mysql56-community

my.cnf:

long_query_time=1
slow-query-log =1 
slow-query-log-file=/var/log/mysql_slow.log
log-queries-not-using-indexes=ON #看情况,是否记录没有走index的语句

default-time-zone='+8:00' #东8区设置

innodb_file_per_table=1
character-set-server = utf8
log_timestamps=system #日志时间是UTC,就要添加,5.7以后一般都需要
max_connections=512
open_files_limit=65535
#以上两个参数在5.6上设置会失败。系统ulimit已经设置为了65535,
#5.7上设置需要注意以下:ulimit -n值要大于设置的值,mysql启动文件中加以下配置:
LimitNOFILE=65535
LimitNPROC=65535
然后:systemctl daemon-reload

binlog最好开启:

expire_logs_days = 99
log-bin = /data/mysql_data/mysql-bin
binlog_format=STATEMENT/mixed/row
server_id=3

 

客户端设置

[client]

default-character-set = utf8

服务端的字符集设置

[mysqld]

character-set-server = utf8

collation-server = utf8_general_ci

 

三、php的安装

yum源网站:https://webtatic.com/packages/

yum源2:

1. First start by installing the EPEL repository and followed by the REMI repository on your system, as follows.

# yum update && yum install epel-release
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm  
2. Next, you need to install yum-utils, a collection of utilities to extend yum’s default features; they help you manage yum repositories as well as packages without any manual configuration and more.

# yum install yum-utils
3. Once you have yum-utils installed, use yum-config-manager to enable Remi repository as the default repository for installing different PHP versions and modules.

# yum-config-manager --enable remi-php55		#For PHP 5.5
# yum-config-manager --enable remi-php56		#For PHP 5.6
# yum-config-manager --enable remi-php70 		#For PHP 7.0
# yum-config-manager --enable remi-php71		#For PHP 7.1
# yum-config-manager --enable remi-php72		#For PHP 7.2

 

 

 yum install php56w  php56w-bcmath php56w-cli php56w-common php56w-fpm php56w-gd \
php56w-mysqlnd php56w-pdo php56w-mbstring php56w-mcrypt php56w-devel php56w-xml php56w-process

 yum install php70w  php70w-bcmath php70w-cli php70w-common php70w-fpm php70w-gd  \
php70w-mysqlnd php70w-pdo php70w-mbstring php70w-mcrypt php70w-devel php70w-xml php70w-process

php.ini:

expose_php = Off 
register_globals = Off 
disable_functions = system,passthru,exec,shell_exec,popen,phpinfo
error_log=/var/log/php-fpm/php_error.log
;allow_url_fopen = Off 
#以下两项是默认的。
max_execution_time = 30 
display_errors = Off 

date.timezone = Asia/Shanghai

php-fpm.conf:

[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 16
pm.min_spare_servers = 10
pm.max_spare_servers = 35
pm.max_requests = 300 
slowlog = /var/log/php-fpm/www-slow.log
rlimit_files = 65535
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache

chown -R nginx  /var/lib/php/session

chown -R nginx /var/log/php-fpm

pm.max_requests#注意这个参数的使用

php与nginx结合

以下两种是相同的:

第一种:
location ~ .+\.php($|/) {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        root  $root_path;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        include        fastcgi_params;
	include 	fastcgi.conf;
       }

第二种:
location ~ .+\.php($|/) {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        root  $root_path;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        include        fastcgi_params;
	fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
	#include 	fastcgi.conf;
       }

如果有时候nginx配置文件中没有fastcgi.conf这个文件,我们只需要加上以下就可以了,因为fastcgi.conf 与fastcgi_param相比多下面一行,其余都一样的。

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

有些php框架,没有上面一行,可能就会报404,及日志中报:FastCGI sent in stderr: “Primary script unknown” 或者没有任何显示。

 

 

四、redis扩展安装

http://pecl.php.net/package/redis

php7.0以下可以安装redis 2.2.8

 

五、phalcon扩展安装

https://github.com/phalcon/cphalcon

 

六、grpc,protobuf

最好是在centos7上编译安装,不然可能会失败。

docker 生成客户端文件
https://grpc.io/docs/quickstart/php.html

grpc及protobuf安装:
https://github.com/grpc/grpc/tree/master/src/php

 

 

 

原文链接:LNMP一键安装,yum安装,转载请注明来源!

2