LNMP是Linux+Nginx+MySQL+PHP的簡稱php
• 和LAMP不一樣的是,提供web服務的是Nginx,而且php是做爲一個獨立服務存在的,叫作php-fpm。css
• Nginx直接處理靜態請求,動態請求會轉發給php-fpm,Nginx處理靜態請求的能力要高於Apache。html
MySQL的幾個經常使用安裝包:rpm、源碼、二進制免編譯mysql
二進制包是區分平臺的,centos7以前的版本都是區分32位和64位,centos7直接選擇64位安裝。linux
[root@linux-10 src]# uname –i //查看linux是多少位 x86_64
[root@linux-10 ~]# cd /usr/local/src //建議將全部軟件包都放在這個目錄下
下載地址到r.aminglinux.com找最新的下載nginx
[root@linux-10 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
注:本人因爲網絡問題,沒法直接將安裝包下載至Linux操做系統中,故採用先下載至本地Windows系統上(版本5.6.35),後經過rz命令上傳至Linux操做系統上web
[root@linux-10 src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@linux-10 src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql [root@linux-10 ~]# cd /usr/local/mysql [root@linux-10 mysql]# ls bin data include man README share support-files COPYING docs lib mysql-test scripts sql-bench
[root@linux-10 mysql]# useradd -s /sbin/nologin mysql
[root@linux-10 mysql]# mkdir /data
[root@linux-10 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql //--user=mysql 以用戶mysql身份運行,--datadir=/data/mysql存放數據庫的目錄 ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper //這裏出現了錯誤,緣由是缺乏包 perl-Module-Install 可使用yum list 來查看缺乏包 [root@linux-10 mysql]# yum list |grep perl |grep -i dumper Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast perl-Data-Dumper.x86_64 2.145-3.el7 base perl-Data-Dumper-Concise.noarch 2.020-6.el7 epel perl-Data-Dumper-Names.noarch 0.03-17.el7 epel perl-XML-Dumper.noarch 0.81-17.el7 base 安裝perl-Data-Dumper包 [root@linux-10 mysql]# yum install -y perl-Data-Dumper
[root@linux-10 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 若是看到兩個OK說明執行正確,或者echo $? 結果爲0 也表示執行正確。 [root@linux-10 mysql]# echo $? 0
Mysql的配置文件在/usr/local/mysql/support-files/目錄下my-default.cnf,它是msyql的模板配置文件sql
[root@linux-10 mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"? y //這裏已經存在文件my.cnf,這是以前系統rpm安裝留下的,咱們能夠查看它是哪一個包安裝的 [root@linux-10 mysql]# rpm -qf /etc/my.cnf mariadb-libs-5.5.52-1.el7.x86_64
咱們這裏直接按「y」覆蓋便可數據庫
[root@linux-10 ~]# vim /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. basedir = /usr/local/mysql //mysql的安裝目錄 datadir = /data/mysql //存放數據庫的目錄 port = 3306 //端口 # server_id = ..... //mysql的ID號,作主從的時候要用到 socket = /tmp/mysql.sock //mysql服務監聽的套件字地址,也是用來通訊的。 # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M
[root@linux-10 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@linux-10 mysql]# vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql
[root@linux-10 mysql]# chmod 755 /etc/init.d/mysqld
[root@linux-10 mysql]# chkconfig --add mysqld
[root@linux-10 mysql]# chkconfig mysqld on
[root@linux-10 ~]# service mysqld start Starting MySQL.Logging to '/data/mysql/linux-5.err'. . SUCCESS!
注:若是啓動不了,請到/data/mysql/目錄下查看錯誤日誌,這個日誌一般是主機名.errapache
[root@linux-10 ~]# ps aux |grep mysqld root 3233 0.0 0.0 11772 1596 pts/1 S 19:58 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/linux-5.pid mysql 3395 0.8 24.0 973052 449444 pts/1 Sl 19:58 0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/linux-5.err --pid-file=/data/mysql/linux-5.pid --socket=/tmp/mysql.sock --port=3306 root 3443 0.0 0.0 112676 984 pts/1 S+ 20:01 0:00 grep --color=auto mysqld
[root@linux-10 ~]# netstat -lnp |grep mysqld tcp6 0 0 :::3306 :::* LISTEN 3395/mysqld unix 2 [ ACC ] STREAM LISTENING 55465 3395/mysqld /tmp/mysql.sock
若是咱們不知道mysql的啓動文件,咱們還可使用命令行的方法來啓動mysql 先關閉以前打開的mysql
[root@linux-10 mysql]# service mysqld stop Shutting down MySQL.. SUCCESS!
執行命令行
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql & //--defaults-file=/etc/my.cnf指定配置文件的路徑
和LAMP安裝PHP方法有差異,須要開啓php-fpm服務
cd /usr/local/src/ wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2
tar jxvf php-5.6.32.tar.bz2
useradd -s /sbin/nologin php-fpm
cd /usr/local/src/php-5.6.32/ ./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 //--prefix=/usr/local/php-fpm 指定安裝目錄 //--with-config-file-path=/usr/local/php-fpm/etc 指定PHP配置文件所在路徑(PHP配置文件後綴爲.ini) //--enable-fpm 啓動fpm服務 // --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with- mysqli=/usr/local/mysql/bin/mysql_config 三種鏈接MySQL的驅動
初始化報錯,須要curl包
yum -y install libcurl-devel
make && make install
/usr/local/php-fpm/sbin/php-fpm -m /usr/local/php-fpm/sbin/php-fpm -i
/usr/local/php-fpm/sbin/php-fpm -t //檢測自身配置語法錯誤
cp php.ini-production /usr/local/php-fpm/etc/php.ini //生產環境 cp php.ini-development /usr/local/php-fpm/etc/php.ini //研發環境
[root@linux-10 php-5.6.32]# cd /usr/local/php-fpm/etc [root@linux-10 etc]# vim php-fpm.conf [global] pid = /usr/local/php-fpm/var/run/php-fpm.pid //pid存放路徑 error_log = /usr/local/php-fpm/var/log/php-fpm.log //錯誤日誌存放路徑 [www] listen = /tmp/php-fcgi.sock //監聽地址,用於服務間通訊 listen.mode = 666 //sock文件的權限 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
注:監聽地址(listen)也能夠寫成listen = 127.0.0.1:9000的格式,由於php-fpm是內部服務,因此採用迴環地址通訊便可,默認端口爲9000。可是兩種配置格式的不一樣,會致使後續相關配置的格式也有所不一樣。
cd /usr/local/src/php-5.6.32 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
[root@linux-10 php-5.6.32]# service php-fpm start Starting php-fpm done
[root@linux-10 php-5.6.32]# ps aux |grep php-fpm root 4790 0.0 0.2 123652 4944 ? Ss 10:40 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 4791 0.0 0.2 123652 4708 ? S 10:40 0:00 php-fpm: pool www php-fpm 4792 0.0 0.2 123652 4708 ? S 10:40 0:00 php-fpm: pool www php-fpm 4793 0.0 0.2 123652 4708 ? S 10:40 0:00 php-fpm: pool www php-fpm 4794 0.0 0.2 123652 4708 ? S 10:40 0:00 php-fpm: pool www php-fpm 4795 0.0 0.2 123652 4712 ? S 10:40 0:00 php-fpm: pool www php-fpm 4796 0.0 0.2 123652 4712 ? S 10:40 0:00 php-fpm: pool www php-fpm 4797 0.0 0.2 123652 4712 ? S 10:40 0:00 php-fpm: pool www php-fpm 4798 0.0 0.2 123652 4712 ? S 10:40 0:00 php-fpm: pool www php-fpm 4799 0.0 0.2 123652 4712 ? S 10:40 0:00 php-fpm: pool www php-fpm 4800 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4801 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4802 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4803 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4804 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4805 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4806 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4807 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4808 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4809 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www php-fpm 4810 0.0 0.2 123652 4716 ? S 10:40 0:00 php-fpm: pool www root 4812 0.0 0.0 112720 968 pts/0 R+ 10:40 0:00 grep --color=auto php-fpm
• Nginx官網 nginx.org,最新版1.15,最新穩定版1.14
• Nginx應用場景:web服務、反向代理、負載均衡
• Nginx著名分支,淘寶基於Nginx開發的Tengine,使用上和Nginx一致,服務名,配置文件名都同樣,和Nginx的最大區別是Tenging增長了一些定製化模塊,在安全限速方面表現突出,另外它支持對js,css合併
• Nginx核心+lua相關的組件和模塊組成了一個支持lua的高性能web容器openresty