1. 程式人生 > >2018-04-23 Linux學習

2018-04-23 Linux學習

Linux學習

12.1 LNMP架構介紹

和LAMP不同的是,提供web服務的是 Nginx
並且 PHP 是作為一個獨立服務存在的,這個服務叫做php-fpm
Nginx 直接處理靜態請求,動態請求會轉發給php-fpm

12.2 MySQL安裝

    cd /usr/local/src
    wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
    tar zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
    mv mysql-5.6.39-linux-glibc2.12-x86_64 /usr/local/mysql
    cd /usr/local/mysql
    useradd mysql     (或 useradd -r -m -d /data/mysql -s /sbin/nologin mysql )
    mkdir /data/
    ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
    cp support-files/my-default.cnf /etc/my.cnf
    cp support-files/mysql.server /etc/init.d/mysqld
    vi /etc/init.d/mysqld
        定義 basedir 和 datadir
        basedir=/usr/local/mysql
        datadir=/data/mysql
    /etc/init.d/mysqld start

12.3-4 PHP安裝

PHP安裝

和LAMP安裝PHP方法有差別,需要開啟php-fpm服務

cd /usr/local/src

wget http://cn2.php.net/distributions/php-5.6.34.tar.gz
tar zxvf php-5.6.34.tar.gz
useradd -r -s /sbin/nologin php-fpm

cd php-5.6.34

./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
make & make install

yum install -y libcurl-devel

/usr/local/php-fpm/sbin/php-fpm -m
/usr/local/php-fpm/sbin/php-fpm -i
/usr/local/php-fpm/sbin/php-fpm -t

ls /usr/local/php-fpm/etc/

cp php.ini-production /usr/local/php-fpm/etc/php.ini
vim /usr/local/php-fpm/etc/php-fpm.conf
    [global]
    pid = /usr/local/php-fpm/var/run/php-fpm.pid
    error_log = /usr/local/php-fpm/var/log/php-fpm.log
    [www]
    listen = /tmp/php-fcgi.sock
    #listen = 127.0.0.1:9000
    listen.mode = 666
    user = php-fpm
    group = php-fpm
    pm = dynamic
    pm.max_children = 50
    pm.start_servers = 20
    pm.min_spare_servers = 5
    pm.max_spare_servers = 35
    pm.max_requests = 500
    rlimit_files = 1024

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig -add php-fpm
chkconfig php-fpm on
service php-fpm start
ps aux |grep php-fpm

操作過程

[root@linux01 ~]# cd /usr/local/src/
[root@linux01 src]# tar zxvf php-7.2.4.tar.gz
[root@linux01 src]# cd php-7.2.4/
[root@linux01 php-7.2.4]# useradd -r -s /sbin/nologin php-fpm

[root@linux01 php-7.2.4]# yum install -y libcurl-devel

[root@linux01 php-7.2.4]# yum install -y libxml2-devel
[root@linux01 php-7.2.4]# yum install -y openssl-devel

[root@linux01 php-7.2.4]# yum install -y libjpeg-turbo-devel
[root@linux01 php-7.2.4]# yum install -y libpng-devel
[root@linux01 php-7.2.4]# yum install -y freetype-devel

[root@linux01 php-7.2.4]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl

[root@linux01 php-7.2.4]# make
[root@linux01 php-7.2.4]# make install

[root@linux01 php-7.2.4]# /usr/local/php-fpm/sbin/php-fpm -m
[root@linux01 php-7.2.4]# /usr/local/php-fpm/sbin/php-fpm -i
[root@linux01 php-7.2.4]# /usr/local/php-fpm/sbin/php-fpm -t

[root@linux01 php-7.2.4]# ls /usr/local/php-fpm/etc/
pear.conf php-fpm.conf.default

[root@linux01 php-7.2.4]# cp php.ini-production /usr/local/php-fpm/etc/php.ini
[root@linux01 php-7.2.4]# vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

[root@linux01 php-7.2.4]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@linux01 php-7.2.4]# chmod 755 /etc/init.d/php-fpm
[root@linux01 php-7.2.4]# chkconfig -add php-fpm
[root@linux01 php-7.2.4]# chkconfig php-fpm on
[root@linux01 php-7.2.4]# service php-fpm start
[root@linux01 php-7.2.4]# ps aux |grep php-fpm

12.5 Nginx介紹

 Nginx官網 nginx.org,最新版1.13,最新穩定版1.12 
 Nginx應用場景:web服務、反向代理、負載均衡
 Nginx著名分支,淘寶基於Nginx開發的Tengine,使用上和Nginx一致,服務名,配置文件名都一樣,和Nginx的最大區別在於Tenging增加了一些定制化模塊,在安全限速方面表現突出,另外它支持對js,css合並
 Nginx核心+lua相關的組件和模塊組成了一個支持lua的高性能web容器openresty,參考http://jinnianshilongnian.iteye.com/blog/2280928

2018-04-23 Linux學習