一,mysql源码编译安装:
安装:
get mysql-boost-5.7.11.tar.gz
tar zxf mysql-boost-5.7.11.tar.gz
get cmake-2.8.12.2-4.el6.x86_64.rpm
cd mysql-5.7.11/
yum install -y gcc gcc-c++ ncurses-devel bison
[root@server4 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 ##Unix socket 文件路径
-DWITH_INNOBASE_STORAGE_ENGINE=1 #安装 innodb 存储引擎
-DWITH_MYISAM_STORAGE_ENGINE=1 #安装 myisam 存储引擎
-DDEFAULT_CHARSET=utf8 #使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci #校验字符
-DEXTRA_CHARSETS=all #安装所有扩展字符集
-DWITH_BOOST=/root/mysql-5.7.11/boost/boost_1_59_0/
make
make install
- 初始化:
groupadd -g 27 mysql
useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/ mysql
id mysql
usermod -s /sbin/nologin mysql
tail -n 1 /etc/passwd
vim .bash_profile
添加在PATH后面:/usr/local/lnmp/mysql/bin/
source .bash_profile
cp /etc/my.cnf /etc/my.cnf.bak
vim /etc/my.cnf
datadir=/usr/local/lnmp/mysql/data
socket=/usr/local/lnmp/mysql/data/mysql.sock
cd /usr/local/lnmp/mysql
chown mysql.mysql . -R
cp mysql.server /etc/init.d/mysqldcp mysql.server #启动脚本
mysqld --initialize --user=mysql #初始化
/etc/init.d/mysqld start
mysql_secure_installation
mysql -p
- 二,php安装:
tar jxf php-5.6.20.tar.bz2
cd php-5.6.20
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local//lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-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
#安装库
yum install -y libxml2-devel openssl-devel curl-devel gd-devel-2.0.35-11.el6.x86_64.rpm gmp-devel libmcrypt-devel-2.5.8-9.el6.x86_64.rpm re2c-0.13.5-1.el6.x86_64.rpm net-snmp-devel
make && make install
- 初始化php:
cd /usr/local/lnmp/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
21 [global]
22 ; Pid file
23 ; Note: the default prefix is /usr/local/lnmp/php/var
24 ; Default Value: none
25 pid = run/php-fpm.pid #去掉注释
cd php-5.6.20
cp php.ini-production /usr/local/lnmp/php/etc/php.ini
vim php.ini
925 date.timezone =Asia/Shanghai
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
useradd -u 800 -M -d /usr/local/lnmp/nginx nginx
/etc/init.d/php-fpm start
- 安装nginx:
cd nginx-1.10.1
vim nginx-1.10.1/src/core/nginx.h
14 #define NGINX_VER "nginx"
vim nginx-1.10.1/auto/cc/gcc
178 # debug
179 #CFLAGS="$CFLAGS -g"
yum install -y pcre-devel
cd nginx-1.10.1
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --user=nginx --group=nginx
make && make install
ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
nginx
- php和nginx关联:
vim /usr/local/lnmp/nginx/html/index.php
<?php
phpinfo()
?>
vim /usr/local/lnmp/nginx/conf/nginx.conf
27 sendfile on;
28 tcp_nopush on;
29 tcp_nodelay on;
33 gzip on;
43 location / {
44 root html;
45 index index.php index.html index.htm;
46 }
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_ script_name;
70 include fastcgi.conf;
71 }
nginx -s reload
- php和数据库关联:
vim /usr/local/lnmp/php/etc/php.ini
1001 pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.so ck
1151 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
1211 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
vim /usr/local/lnmp/nginx/conf/nginx.conf
117 server {
118 listen 80;
119 server_name bbs.westos.com;
120 location / {
121 root /bbs;
122 index index.php;
123 }
124 location ~ \.php$ {
125 root /bbs;
126 fastcgi_pass 127.0.0.1:9000;
127 fastcgi_index index.php;
128 include fastcgi.conf;
129 }
130 }
mkdir /bbs
解压论坛包
unzip Discuz_X3.2_SC_UTF8.zip
mv upload/ /bbs
chmod 777 config/ data uc_client/ uc_server/ -R
浏览器访问:bbs.westos.com/install 进行论坛安装 #做之前先要在本地加解析
这种问题是要修改数据库data目录权限:
cd /usr/local/lnmp/mysql/
chmod 755 data
到此LNMP架构配置成功!
添加memcached缓存:
memcached是一种缓存软件,以键值的形式缓存数据,支持缓存数据大大小为48kb到1Mb,memcached只是将缓存数据写在内存中,不会写入硬盘,同时,memcached缓存不可架设高可用,但是可以部署分布式memcached缓存服务器。而对于同样具有缓存功能的redis来说。redis是一种负载型数据结构缓存,如一键多值,redis也在内存中缓存,但是它可以将数据写入磁盘,是一种数据结构性NOSQL型数据库,不支持SQL语句查询
server5上:memcached缓存服务器
yum install -y memcached telnet
/etc/init.d/memcached start
#测试memcached服务器,交互式写入数据
#注意;memcached数据存储在内存中
#memcache是一个键值数据库
[root@server5 ~]# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
set name 0 0 6 #在缓存中添加6个字符的‘key‘
tomtom
STORED
get name #获取添加的key
VALUE name 0 6
tomtom
END
set name 0 0 4 #在缓存中添加4个字符的‘key‘
tomtom
CLIENT_ERROR bad data chunk #添加6个字符的key时出错
ERROR
- server4上:
vim .bash_profile
/usr/local/lnmp/php/bin
source .bash_profile
tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5
[root@server4 memcache-2.2.5]# phpize #生成configure
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@server4 memcache-2.2.5]# ./configure --prefix=/usr/local/lnmp/php/memcache
make && make install
vim /usr/local/lnmp/php/etc/php.ini
862 extension=memcache.so #php扩展指向memcached的动态连接库文件
[root@server4 memcache-2.2.5]# cp example.php memcache.php /usr/local/lnmp/nginx/html/
[root@server4 memcache-2.2.5]# vim /usr/local/lnmp/nginx/html/example.php #example.php是php开发的用来往memcache中添加数据的程序页
3 $memcache = memcache_connect('172.25.92.5', 11211); #指定memcache服务器
4
5 if ($memcache) {
6 $memcache->set("str_key", "memcache success"); #往memcache中添加的key
7 $memcache->set("num_key", 123);
#添加的value
[root@server4 memcache-2.2.5]# vim /usr/local/lnmp/nginx/html/memcache.php #查看memcache的缓存页面
22 define('ADMIN_USERNAME','memcache'); // Admin Username #登陆界面的用户名
23 define('ADMIN_PASSWORD','westos'); // Admin Password #登陆界面的密码
28 $MEMCACHE_SERVERS[] = '172.25.92.5:11211'; // add more as an a rray #指定memcache服务器
[root@server4 memcache-2.2.5]# /etc/init.d/php-fpm reload
- 查看效果:
在server5上可以看到锁添加的key和value:
[root@server5 ~]# telnet localhost 11211
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
get str_key #在example.php文件中添加的key
VALUE str_key 0 16
memcache success
END
get num_key
VALUE num_key 0 3
123
END
在浏览器端: