第一步安装nginx1.10.3

优化nginx的介绍:jemalloc
https://ideas.spkcn.com/software/os/linux/577.html
预先安装autoconf 和 make
yum -y install autoconf make
jemalloc的安装
jiemalloc 开源项目网站 http://www.canonware.com/jemalloc/
wget https://github.com/jemalloc/jemalloc/releases/jemalloc-4.2.1.tar.bz2
tar -xjf jemalloc-4.2..tar.bz2
cd jemalloc-4.2.
./configure --prefix=/usr/local/jemalloc --libdir=/usr/local/lib
make && make install
make clean
cd ../
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig 使用jemalloc优化MYSQL数据库
MYSQL或者MariaDB源码编译时添加以下参数
-DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" -DWITH_SAFEMALLOC=OFF
或者编辑mysqld_safe文件直接加载:
查找文件 /usr/local/mysql/bin/mysqld_safe
在# executing mysqld_safe 下面加上 LD_PRELOAD=/usr/local/lib/libjemalloc.so
重新启动MYSQL 使用下面代码自动修改mysqld_safe文件
sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' /usr/local/mysql/bin/mysqld_safe service mysqld restart
使用jemalloc优化NGINX
编译NGINX时添加以下参数:
--with-ld-opt="-ljemalloc" 验证 jemalloc 是否运行:
lsof -n | grep jemalloc

这个配置稍后在lnmp第二部分,此处没有mysqld的优化。
nginx基础环境搭建:

service iptables stop
iptables -I INPUT -p tcp --dport -j ACCEPT
vi /etc/sysconfig/selinux
selinux=disabled 创建文件夹
mkdir -p /usr/local/src
cd /usr/local/src 用户
useradd -s /sbin/nologin -M www
groupadd nginx 下载稳定版nginx1.10.3
yum -y install zlib* gcc gcc-c++ libtool openssl* automake autoconf libtool pcre*
wget http://nginx.org/download/nginx-1.10.3.tar.gz
cd nginx-1.10.
./configure --help ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-ld-opt='-ljemalloc'
--with-ld-opt这个优化的是nginx内存参数。 make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin 创建家目录
mkdir -p /home/wwwlogs/
mkdir -p /usr/local/nginx/logs/
将编写好的nginx.conf 拷贝到nginx.conf
创建vhost,并属主属组,
chown -R www:www /home/wwwroot/
mkdir -p /home/wwwroot/ /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -v
/usr/local/nginx/sbin/nginx -t netstat -antpu | grep nginx
curl ip地址 :查看能否正常运行nginx。
关于pid报错的信息,killall - nginx
编写自己启动文档。

[root@test1 html]# cat /usr/local/nginx/conf/nginx.conf

user  www www;
worker_processes auto;
#error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile ; events
{
use epoll;
worker_connections ;
multi_accept on;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size ;
client_header_buffer_size 32k;
large_client_header_buffers 32k;
client_max_body_size 50m; sendfile on;
tcp_nopush on; keepalive_timeout ;
tcp_nodelay on; fastcgi_connect_timeout ;
fastcgi_send_timeout ;
fastcgi_read_timeout ;
fastcgi_buffer_size 64k;
fastcgi_buffers 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k; gzip on;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_http_version 1.1;
gzip_comp_level ;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\."; #limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section. server_tokens off;
access_log off; include vhost/*.conf;
}

在nginx的配置文件中

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000; 该处必须和php-fpm.conf中的lisen一样
#fastcigi_pass /tmp/php-cgi.sock
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

官网下载mysql(该配置文件没有优化mysql内存)

下载MySQL5..20源码包,和boost
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz
wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/ 添加用户和组MySQL,并且不允许登录
groupadd mysql
usradd -r -g mysql -s /sbin/nologin -M mysql
配置环境,解压包
yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake
tar -xf mysql-5.7..tar.gz
cd mysql-5.7.
mkdir -p /usr/local/mysql/
mkdir -p /usr/local/boost/
cp boost_1_59_0.tar.gz /usr/local/boost 将包放到boost下
mkdir -p /data/mysql
其中data下的属主和属组必须是mysql,date是数据库目录。
ls /usr/local/mysql
chown -R mysql:mysql /data/mysql cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE= -DWITH_INNOBASE_STORAGE_ENGINE= -DWITH_ARCHIVE_STORAGE_ENGINE= -DWITH_BLACKHOLE_STORAGE_ENGINE= -DENABLED_LOCAL_INFILE= -DMYSQL_DATADIR=/data/mysql -DDOWNLOAD_BOOST= -DMYSQL_TCP_PORT= -DENABLE_DOWNLOADS= -DWITH_BOOST=/usr/local/boost -DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" -DWITH_SAFEMALLOC=OFF 此处做优化内容。
make && make install 将安装目录添加到环境变量中:
echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
source /etc/profile
查看文件错误日志出现这行信息,
说明文件没有初始化,需要删除/data/mysql(数据库目录)下的文档
--18T15::.477533Z [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
--18T15::.477899Z [ERROR] unknown variable 'default-file=/etc/my.cnf'
--18T15::.477915Z [ERROR] Aborting 初始化安装MySQL
cd /data/mysql 每次初始化时都要删除该目录下文件(数据库目录)
rm -rf ./*
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql \
--basedir=/usr/local/mysql --datadir=/data/mysql ps aux | grep mysql
会出现如下内容:
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
mysql 27672 0.1 2.5 914052 49200 pts/1 Sl 00:11 0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/mysql-error.log --open-files-limit=65535 --pid-file=/usr/local/mysql/mysql.pid --socket=/usr/local/mysql/mysql.sock --port=3306
root 27721 0.0 0.0 103260 876 pts/1 S+ 00:15 0:00 grep 3306 6 配置my.cnf
在启动mysql服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到会搜索
$basedir/my.cnf 也就是安装目录,新版的配置文件默认位置。将/etc下的my.cnf备份
否则该文件会影响安装mysql的正确配置,造成无法启动。
cp my-default.cnf /etc/my.cnf
后台启动MySQL /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
正常启动后没有其他内容,回车一下就出来了。 查看MySQL是否启动
ps -aux | grep mysql
将启动的MySQL杀死
kill -9 进程号(两个)
只留下一个就好了:root 80654 0.0 0.0 103256 840 pts/1 S+ 08:18 0:00 grep mysql cd /usr/local/mysql/support-files
将其中的mysql-server复制到启动程序下,并改名为mysqld
cp mysql-server /etc/init.d/
mv mysql-server /etc/init.d/mysqld
chmod 755 mysqld 修改vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql 启动程序
/etc/init.d/mysqld restart 设置开机自启
chkconfig mysqld on
chkconfig --add mysqld 修改mysqld的密码
vi /etc/my.cnf
在mysqld下添加:skip-grant-tables
service mysqld restart
mysql -u root -p 此时密码为空
登录并修改mysql的root密码:
>use mysql;
>update user set authentication_string=password('123456') where user='root';
>flush privileges;
>quit
在5.7的版主中原来的password改为:authertication_string
在>select * from mysql.user \G; 中得到。
删除skip-grant-tables
重启服务

mysql -v

关于mysql配置过程中出错的问题

启动MySQL时出错:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 32519
[root@slave1 mysql]# 2017-12-20T12:50:13.972444Z mysqld_safe error:
log-error set to '/usr/local/mysql/mysql-error.log',
however file don't exists. Create writable for user 'mysql'.
解决办法:
echo "" > /usr/local/mysql/mysql-error.log
chown -R mysql:mysql /usr/local/mysql/mysql-error.log
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &

关于pid的问题
当初始化时会产生一个pid,所以每次读取配置文件都要读取该pid
pid报错时候,用service mysqld restart不能读取,应该用
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
然后从错误的文档中查看。出现的报错信息时间会对不上,找最近的。

关于cmake时报错
CMake Error at cmake/boost.cmake:76 (MESSAGE):
Call Stack (most recent call first):
  cmake/boost.cmake:228 (COULD_NOT_FIND_BOOST)
 
  CMakeLists.txt:435 (INCLUDE)
 
 解决方法一:
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/data
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock
-DMYSQL_USER=mysql
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DENABLED_LOCAL_INFILE=ON
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/local/boost

解决方法二:
下载boost包,放到/usr/local/boost目录下,
cmake后面加选项 -DWITH_BOOST=/usr/local/boost

关于sock问题
2018-01-15T03:10:11.729108Z 0 [ERROR] Could not create unix socket lock file /usr/local/mysql/mysql.sock.lock.
2018-01-15T03:10:11.729117Z 0 [ERROR] Unable to setup unix socket lock file.
尝试给my.cnf备份,然后在将my.cnf中的socket改下路径

vi /etc/my.cnf

[root@test1 html]# cat /etc/my.cnf
[client]
port =
socket = /data/mysql/mysql.sock
#default-character-set = utf8mb4
[mysqld]
port =
socket = /data/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id =
log-bin=/data/mysql/mysql-bin/mysql-bin
relay-log=/data/mysql/relay-bin/relay-bin
slow_query_log_file = /data/mysql/mysql-slow.log
#init-connect = 'SET NAMES utf8mb4'
log_error = /data/mysql/mysql-error.log
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
#skip-grant-tables
log-slave-updates
binlog_format = mixed
#binlog-ignore-db=mysql,information_schema,sys,performance_schema
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
back_log =
max_connections =
max_connect_errors =
open_files_limit =
table_open_cache =
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size =
query_cache_type =
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len =
expire_logs_days =
slow_query_log =
long_query_time =
performance_schema =
explicit_defaults_for_timestamp
#lower_case_table_names =
skip-external-locking
innodb_file_per_table =
innodb_open_files =
innodb_buffer_pool_size = 64M
innodb_write_io_threads =
innodb_read_io_threads =
innodb_thread_concurrency =
innodb_purge_threads =
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_lock_wait_timeout =
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads =
interactive_timeout =
wait_timeout =
init-connect = 'SET NAMES utf8mb4'
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
wget http://cn2.php.net/distributions/php-5.6.10.tar.gz
tar -zxvf php-5.6..tar.gz
cd php-5.6.
./configure --help
yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel gcc gcc-c++
yum install -y epel-release
yum -y install libmcrypt libmcrypt-devel freetype-devel
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo make && make install 指定 php 安装目录
--prefix=/usr/local/php # 指定php.ini位置
--with-config-file-path=/etc

# mysql安装目录,对mysql的支持
--with-mysql=/usr/local/mysql find / -name mysql.h 找到mysql.h的路径
/usr/local/mysql/include/mysql.h
/usr/local/src/mysql-5.7./include/mysql.h
/usr/local/src/mysql-5.7./rapid/plugin/x/mysqlxtest_src/mysqlx/mysql.h --with-mysql=/usr #这是mysql相关编译路径,这里网上很多都是--with-mysql=/usr/share/mysql,但我这样做,编译完提示一个error,Cannot find MySQL header files under /usr/share/mysql ,经查,有的说是因为64位电脑的原因,此处正确写法是 先 用 find / -name mysql.h 找到mysql.h的路径,然后写该路径的前缀。比如我电脑搜出来路径/usr/local/mysql/include/mysql.h ,所以前缀是 /usr/local/mysql --with-mysql-sock --with-mysqli=
# 这应该是mysqli 编译配置,后面的参数可以先 find / -name mysql_config
/usr/local/mysql/bin/mysql_config
/usr/local/src/mysql-5.7./scripts/mysql_config --enable-fpm # 开启php-fpm 功能
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/src/php-5.6./sapi/fpm/
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
service php-fpm start
chkconfig --add php-fpm
chkconfig php-fpm on
将配置文件中的php-fpm.conf文档复制下。
重启服务
service php-fpm restart 如果在cmake的时候没有指定为用户和用户组www,
可以在php-fpm.conf配置文件中,添加include php-fpm.d/*.conf
然后在创建php-fpm.d文件夹。在该文件夹下创建www.conf
ln -s /usr/local/php/etc/php.ini /etc/php.ini
如果不添加如下,php -v读不出来 export PATH=/usr/local/php/bin:$PATH
source /etc/profile
vi /usr/local/php/etc/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

安装php5.6版本

查看编译:/usr/local/php/sbin/php -i | grep configure

[www]
;listen = /tmp/php-cgi.sock listen = 127.0.0.1:
listen.backlog = -
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode =
user = www
group = www
pm = dynamic
pm.max_children =
pm.start_servers =
pm.min_spare_servers =
pm.max_spare_servers =
request_terminate_timeout =
request_slowlog_timeout =
slowlog = var/log/slow.log
pm.status_path = /status 查看nginx,php,mysql编译的参数
nginx: /usr/local/nginx/sbin/nginx -v
php: /usr/local/php/bin/php -i | grep configure
mysql: /usr/local/mysql/bin/mysqlbug | grep configure
ps -ef | grep mysql

测试篇

cat /usr/local/nginx/conf/vhost/test.conf
server {
listen ;
server_name www.test.com; location / {
root html;
index index.php index.html index.htm ;
} error_page /50x.html;
location = /50x.html {
root html;
} location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
} cd /usr/local/nginx/html
cat test.php <?php
phpinfo();
?> chown www.www /usr/local/nginx/html/ -R
chmod /usr/local/nginx/html/ -R

在浏览器中输入服务器IP/test.php地址,会看到php界面
到此,LNMP环境部署完成!

最新文章

  1. listview复用机制研究
  2. Flex数据绑定陷阱(一)
  3. NGINX将PHP带参数的URL地址重定向二级或多级域名访问
  4. VCL主要框架
  5. MySQL 数据库存储引擎
  6. 基于http协议的api接口对于客户端的身份认证方式以及安全措施
  7. button 事件属性
  8. 安装Sublime Text 2插件的方法
  9. UVa 442 (栈) Matrix Chain Multiplication
  10. 【宽搜】XMU 1039 Treausure
  11. return break continue 的区别
  12. web开发性能优化---项目架构篇
  13. 一个HttpWebRequest工具类
  14. cpu95%,查找问题sql
  15. 常用Mysql数据库操作语句
  16. app.use和app.get,app.post区别
  17. db2 表空间扩容
  18. What is event bubbling and capturing?
  19. C++ new 和malloc 区别
  20. django的model操作整理

热门文章

  1. web常用软件
  2. ABAP术语-Lock Mode
  3. ubuntu系统下的docker
  4. 04 shell编程之循环语句
  5. 为何企业钟爱H5响应式网站? html5响应式网站的优势与特点
  6. JS 红包随机
  7. python基础之初识
  8. 关于在各种int类型选择时的考虑
  9. 017---Django的中间件解决跨域
  10. AES128加密-S盒和逆S盒构造推导及代码实现