Lnmp架构
源码编译
第一阶段
Mysql -boost 5.7
1. Mysql 安装
yum install -y gcc gcc-c++ make ncurses-devel bison openssl-devel zlib-devel
yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm
Yum install -y re2c-0.13.5-1.el6.x86_64.rpm
Yum install -y libevent-devel-1.4.13-4.el6.x86_64.rpm
Yum install libevent-doc-1.4.13-4.el6.noarch.rpm
Yum install libevent-headers-1.4.13-4.el6.noarch.rpm
Yum install libmcrypt-2.5.8-9.el6.x86_64.rpm
Yum install
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
1、解压、编译 mysql
###采用 mysql-boost-5.7.11.tar.gz (boost模块自带)
tar zxf mysql-boost-5.7.11.tar.gz
cd mysql-5.7.11/
yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm
##注意: cmake 版本必须是 2.8 及以上
cd mysql-5.7.11/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/
3、编译、安装 make && make install
4、初始化
[root@server1 mysql-5.7.11]# cd /usr/local/lnmp/mysql/support-files
[root@server1 mysql]# cd support-files/
[root@server1 support-files]# ls
magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@server1 support-files]# rpm -qa |grep mysql
mysql-libs-5.1.71-1.el6.x86_64 ## lib 很重要,不要动!!!
[root@server1 support-files]# cd /etc/
[root@server1 etc]# mv my.cnf my.cnf.back ##将原配置文件备份
[root@server1 etc]# cd -
/usr/local/lnmp/mysql/support-files ##将mysql配置文件复制到/etc
[root@server1 support-files]# cp my-default.cnf /etc/my.cnf
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@server1 support-files]# ll /etc/init.d/mysqld ##脚本复制到/etc/init.d/,x权限
-rwxr-xr-x 1 root root 11005 Jun 29 10:55 /etc/init.d/mysqld
[root@server1 mysql]# groupadd -g 27 mysql
[root@server1 mysql]# useradd -u 27 -g 27 -d /usr/local/lnmp/mysql/data -M -s /sbin/nologin mysql
[root@server1 mysql]# useradd -u 27 -g 27 -d /usr/local/lnmp/mysql/data -M -s /sbin/nologin mysql
[root@server1 mysql]# grep mysql /etc/passwd ##新建mysql用户,指定uid、gid和家目录
mysql:x:27:27::/usr/local/lnmp/mysql/data:/sbin/nologin
[root@server1 mysql]# chown mysql.mysql . -R
[root@server1 bin]# pwd ##添加环境变量
/usr/local/lnmp/mysql/bin
[root@server1 bin]# vim /root/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
export PATH
[root@server1 bin]# source /root/.bash_profile
[root@server1 data]# pwd
/usr/local/lnmp/mysql/data
# These are commonly set, remove the # and set as required.
basedir = /usr/local/lnmp/mysql
datadir = /usr/local/lnmp/mysql/data
port = 3306
# server_id = .....
socket = /usr/local/lnmp/mysql/data/mysql.sock
[root@server1 bin]# mysql_install_db ## 老版本的初始化命令,5.6以后新命令
2018-06-29 11:01:28 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-06-29 11:01:28 [ERROR] The data directory needs to be specified.
[root@server1 bin]# mysqld --initialize --user=mysql
A temporary password is generated for root@localhost: _AcXHlHrf4Qk(临时密码)
[root@server1 mysql]# chown root . -R
[root@server1 mysql]# chown mysql data/ -R ##保证 mysql 用户对 data 目录有绝对权限
[root@server1 mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@server1 mysql]# mysql_secure_installation ##安全初始化
##密码强度校验,y|Y:加载该模块,n/N:不检验密码强度
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
4、登陆测试
[root@server1 mysql]# mysql -p
mysql> create database westos;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| westos |
+--------------------+
5 rows in set (0.00 sec)
[root@server1 mysql]# cd data/
[root@server1 data]# ls
auto.cnf ib_logfile0 mysql mysql.sock.lock server1.pid
ib_buffer_pool ib_logfile1 mysqld_safe.pid performance_schema sys
ibdata1 ibtmp1 mysql.sock server1.err westos
# These are commonly set, remove the # and set as required.
basedir = /usr/local/lnmp/mysql
datadir = /usr/local/lnmp/mysql/data
port = 3306
# server_id = .....
socket = /usr/local/lnmp/mysql/data/mysql.sock
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
export PATH
二、Php 源码安装
1、解压、预编译
tar jxf php-5.6.35.tar.bz2
cd php-5.6.35
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
2、解决依赖性
libxml2-devel openssl-devel curl-devel libjpeg-turbo-devel libpng-devel
freetype-devel gmp-devel libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm net-snmp-devel
3、安装 make && make install
4、配置 php
[root@server1 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.35]# cd -
/usr/local/lnmp/php
[root@server1 php]# ls
bin etc include lib php sbin var
[root@server1 php]# cd epwdtc/
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@server1 etc]# vim php-fpm.conf ##打开 pid
[root@server1 etc]# vim php.ini ##设定时区 Asia/Shanghai
5、复制脚本,启动php
root@server1 php-5.6.35]# cd sapi/fpm/
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm
[root@server1 fpm]# /etc/init.d/php-fpm status
php-fpm is stopped
[root@server1 fpm]# /etc/init.d/php-fpm start
Starting php-fpm done
四、搭建论坛,LNMP架构
1、在 /usr/local/lnmp/nginx/html 目录下载 Discuz_X3.2_SC_UTF8.zip
2、安装 unzip,解压 Discuz_X3.2_SC_UTF8.zip
3、访问网页搭建论坛 (重命名 upload -> bbs)
排错:
1、bbs下文件权限不够
[root@server1 bbs]# chmod 777 uc_server/ config/ data/ uc_client/ -R
2、目录不存在
一共修改三个文件
[root@server1 bbs]# vim /usr/local/lnmp/php/etc/php.ini
1013 pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.sock
1162 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
1221 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
[root@server1 bbs]# /etc/init.d/php-fpm reload
Reload service php-fpm done
3、数据库权限不够
[root@server1 bbs]# chmod 755 /usr/local/lnmp/mysql/data/
4、输入数据库密码,设定 admin 密码,搭建成功
5、避免重复安装,删除 /usr/local/lnmp/nginx/html/bbs/install/index.php
五、Php 添加新模块
1、解压,配置 memcache-2.2.5
[root@server1 ~]# tar zxf memcache-2.2.5.tgz
2、添加环境变量
[root@server1 bin]# vim ~/.bash_profile
/usr/local/lnmp/php/bin/
[root@server1 bin]# source ~/.bash_profile
3、编译、安装 memcache-2.2.5
[root@server1 ~]# cd memcache-2.2.5
[root@server1 memcache-2.2.5]# phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@server1 memcache-2.2.5]# ./configure
[root@server1 memcache-2.2.5]# make && make install
4、修改配置文件,查看模块是否加载
[root@server1 memcache-2.2.5]# vim /usr/local/lnmp/php/etc/php.ini
874 extension=memcache.so
[root@server1 memcache-2.2.5]# php -m | grep memcache
memcache
## 修改配置文件切记 reload
[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
5、查看 memcache 端口
[root@server1 memcache-2.2.5]# yum install -y memcached
[root@server1 memcache-2.2.5]# /etc/init.d/memcached start
Starting memcached: [ OK ]
[root@server1 memcache-2.2.5]# netstat -antuple | grep memcache
User Inode PID/Program name
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 498 254469 13869/memcached
6、设置 memcache.php
[root@server1 memcache-2.2.5]# cp memcache.php /usr/local/lnmp/nginx/html/
[root@server1 memcache-2.2.5]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# vim memcache.php
22 define('ADMIN_USERNAME','memcache'); // Admin Username
23 define('ADMIN_PASSWORD','westos'); // Admin Password
28 $MEMCACHE_SERVERS[] = '172.25.77.1:11211'; // add more as an array
##访问 172.25.77.1/memcache.php
7、设置 example.php
[root@server1 memcache-2.2.5]# cp example.php /usr/local/lnmp/nginx/html/
##访问 172.25.77.1/example.php
8、物理主机测试
[root@foundation77 ~]# ab -c 10 -n 1000 http://172.25.77.1/example.php
Complete requests: 1000
Failed requests: 0
Write errors: 0
Requests per second: 1728.62 [#/sec] (mean)
[root@foundation77 ~]# ab -c 10 -n 1000 http://172.25.77.1/index.php
Complete requests: 1000
Failed requests: 752
(Connect: 0, Receive: 0, Length: 752, Exceptions: 0)
Write errors: 0
Requests per second: 369.41 [#/sec] (mean)