hq8501 发表于 2018-12-12 10:43:11

lnmp架构介绍,mysql,php安装,Nginx介绍

lnmp架构介绍
http://i2.运维网.com/images/blog/201803/12/97c486e3937c3ff19134407626d347bc.png

MySQL安装
http://i2.运维网.com/images/blog/201803/12/6e99e7a4f75bbbed7c5283fdebd8ec50.png
1.首先下载软件包

# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
--2018-02-26 21:12:00--http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
正在解析主机 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140
正在连接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:316320366 (302M)
正在保存至: “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz”
100%[====================================>] 316,320,366525KB/s 用时 11m 2s
2018-02-26 21:23:02 (467 KB/s) - 已保存 “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz” )

  2.解压缩

tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

  3.移动目录并改名

# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
  4.进入mysql目录

# cd /usr/local/mysql/
# ls
bin      dataincludeman         README   share      support-files
COPYINGdocslib      mysql-testscriptssql-bench

  5.创建用户,目录并初始化

# useradd mysql
# mkdir /data/
# ls /data/
# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
  6.初始化:

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2018-02-26 22:25:59 0 TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-02-26 22:25:59 0 Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-02-26 22:25:59 0 ./bin/mysqld (mysqld 5.6.36) starting as process 1622 ...
2018-02-26 22:25:59 1622 InnoDB: Using atomics to ref count buffer pool pages
2018-02-26 22:25:59 1622 InnoDB: The InnoDB memory heap is disabled
2018-02-26 22:25:59 1622 InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-02-26 22:25:59 1622 InnoDB: Memory barrier is not used
2018-02-26 22:25:59 1622 InnoDB: Compressed tables use zlib 1.2.3
2018-02-26 22:25:59 1622 InnoDB: Using Linux native AIO
  7.执行完成后马上执行

# echo $?
0
  检验上一条是否正确,0为正确
8.复制配置文件,或更改自带文件

# cp support-files/my-default.cnf/etc/my.cnf^C
# ls /etc/my.cnf
/etc/my.cnf
# rpm -qf /etc/my.cnf
mariadb-libs-5.5.56-2.el7.x86_64

  # vim /etc/my.cnf


datadir=/data/mysql
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d

  9.复制启动脚本

# ls support-files/
binary-configuremy-default.cnf       mysql-log-rotate
magic             mysqld_multi.servermysql.server
# cp support-files/mysql.server/etc/init.d/mysqld

  10.更改启动脚本:
# vi /etc/init.d/mysqld


basedir=/usr/local/mysql
datadir=/data/mysql
  11.设置开机启动

# chkconfig --add mysqld
# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies '。
mysqld          0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关
network         0:关 1:关 2:开 3:开 4:开 5:开 6:关

php安装
http://i2.运维网.com/images/blog/201803/12/3b5bd4cae6ff316625df4d655dba4297.png
  1.首先,将之前的php配置清空:

# make clean
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp5.la sapi/cli/php sapi/cgi/php-cgi    libphp5.la modules/* libs/*

  2.重新配置:

./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
![](http://i2.运维网.com/102"=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
  报错

checking whether to enable calendar conversion support... no
checking whether to enable ctype functions... yes
checking for cURL support... yes
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/

  安装依赖包:

# yum install -y libcurl-devel
已加载插件:fastestmirror
base                                                                   | 3.6 kB00:00:00   
epel/x86_64/metalink                                                   | 5.8 kB00:00:00   
epel                                                                   | 4.7 kB00:00:00   
extras                                                               | 3.4 kB00:00:00   
updates                                                                | 3.4 kB00:00:00   
(1/4): extras/7/x86_64/primary_db                                    | 181 kB00:00:00
  再次配置:

./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
![](http://i2.运维网.com/102"=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
  完成
3.安装

# make && make install
/bin/sh /usr/local/src/php-5.6.30/libtool --silent --preserve-dup-deps --mode=compile cc-Iext/opcache/ -I/usr/local/src/php-5.6.30/ext/opcache/ -DPHP_ATOM_INC -I/usr/local/src/php-5.6.30/include -I/usr/local/src/php-5.6.30/main -I/usr/local/src/php-5.6.30 -I/usr/local/src/php-5.6.30/ext/date/lib -I/usr/local/src/php-5.6.30/ext/ereg/regex -I/usr/include/libxml2 -I/usr/include/freetype2 -I/usr/local/src/php-5.6.30/ext/mbstring/oniguruma -I/usr/local/src/php-5.6.30/ext/mbstring/libmbfl -I/usr/local/src/php-5.6.30/ext/mbstring/libmbfl/mbfl -I/usr/local/mysql/include -I/usr/local/src/php-5.6.30/ext/sqlite3/libsqlite -I/usr/local/src/php-5.6.30/TSRM -I/usr/local/src/php-5.6.30/Zend    -I/usr/include -g -O2 -fvisibility=hidden   -c /usr/local/src/php-5.6.30/ext/opcache/ZendAccelerator.c -o ext/opcache/ZendAccelerator.lo

  4.查看文件结构:

# ls /usr/local/php-fpm/
binetcincludelibphpsbinvar
# ls /usr/local/php
binetcincludelibphp
# ls /usr/local/php-fpm/sbin/
php-fpm
# ls /usr/local/php-fpm/var
logrun

  5.查看配置是否正确:

# /usr/local/php-fpm/sbin/php-fpm -t
ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2)
ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf'
ERROR: FPM initialization failed

http://i2.运维网.com/images/blog/201803/12/31dca83fb84ba48ba7704ad859d46c5c.png
6.修改配置文件:

# cp php.ini-production /usr/local/php-fpm/php.ini
# cd /usr/local/php-fpm/etc/
# ls
pear.confphp-fpm.conf.default
# vim php-fpm.conf


pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log

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

  7.开启服务:

# cd /usr/local/src/php-5.6.30
# 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
Starting php-fpm ERROR: cannot get uid for user 'php-fpm'
ERROR: FPM initialization failed
failed

  报错,需要添加用户php-fpm

# useradd php-fpm
# service php-fpm start
Starting php-fpmdone
# ps aux |grep php-fpm
root   1175760.00.4 1236564920 ?      Ss   22:43   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm1175770.00.4 1236564676 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175780.00.4 1236564676 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175790.00.4 1236564676 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175800.00.4 1236564676 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175810.00.4 1236564680 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175820.00.4 1236564680 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175830.00.4 1236564680 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175840.00.4 1236564680 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175850.00.4 1236564680 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175860.00.4 1236564680 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175870.00.4 1236564680 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175880.00.4 1236564680 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175890.00.4 1236564684 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175900.00.4 1236564684 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175910.00.4 1236564684 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175920.00.4 1236564684 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175930.00.4 1236564684 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175940.00.4 1236564684 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175950.00.4 1236564684 ?      S    22:43   0:00 php-fpm: pool www
php-fpm1175960.00.4 1236564684 ?      S    22:43   0:00 php-fpm: pool www
root   1176020.00.0 112676   984 pts/0    R+   22:43   0:00 grep --color=auto
Nginx介绍
http://i2.运维网.com/images/blog/201803/12/f94352886978657c16bc592f377c64b9.png



页: [1]
查看完整版本: lnmp架构介绍,mysql,php安装,Nginx介绍