安装准备:

Centos7.3

MYSQL5.6

PHP5.6

NGINX1.10.3

一、安装Mysql

  1. mysql
    [root@host129 src]#cd /usr/local/src/
  2.  
  3. [root@host129 src]# wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz
  4. [root@host129 src]# tar zxvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz 
  5. [root@host129 src]# mv mysql-5.6.41-linux-glibc2.12-x86_64 /usr/local/mysql
  6. [root@host129 src]# useradd -s /sbin/nologin mysql
  7.  
  8. [root@host129 src]# cd /usr/local/mysql/
  9. [root@host129 mysql]# mkdir -p /data/mysql
  10. [root@host129 mysql]# chown -R mysql:mysql /data/mysql/
  11. [root@host129 mysql]#
  12. [root@host129 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  13. [root@host129 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  14. FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
  15. Data::Dumper
  16. 出现以上报错:安装一下软件,再次执行脚本
  17. [root@host129 mysql]# yum -y install autoconf
  18. [root@host129 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  19. [root@host129 mysql]# cp support-files/my-default.cnf /etc/my.cnf
  20. [root@host129 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
  21. [root@host129 mysql]# chmod /etc/init.d/mysqld
  22. [root@host129 mysql]# vim /etc/init.d/mysqld
  23.  
  24. datadir=/data/mysql
  25.  
  26. [root@host129 mysql]# chkconfig --add mysqld
  27. [root@host129 mysql]# chkconfig mysqld on
  28. [root@host129 mysql]# service mysqld start
  29. Starting MySQL.Logging to '/data/mysql/host129.err'.
  30. . SUCCESS!
  31. [root@host129 mysql]# ps aux | grep mysqld
  32.  
  33. 首次进入mysql
  34. [root@host129 ~]# /usr/local/mysql/bin/mysql -uroot

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41 MySQL Community Server (GPL)

  1. mysql> exit
  2. Bye

二、安装PHP

  1. PHP:
  2. [root@host129 src]#cd /usr/local/src/
  3. [root@host129 src]#wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
  4. [root@host129 src]#tar zxf php-5.6..tar.gz
  5. [root@host129 src]# useradd -s /sbin/nologin php-fpm
  6. [root@host129 src]# cd php-5.6.
  7. [root@host129 php-5.6.]#
  8.  
  9. [root@host129 php-5.6.]# ./configure \
  10. --prefix=/usr/local/php-fpm \
  11. --with-config-file-path=/usr/local/php-fpm/etc \
  12. --enable-fpm \
  13. --with-fpm-user=php-fpm \
  14. --with-fpm-group=php-fpm \
  15. --with-mysql=/usr/local/mysql \
  16. --with-mysql-sock=/tmp/mysql.sock \
  17. --with-libxml-dir \
  18. --with-gd \
  19. --with-jpeg-dir \
  20. --with-png-dir \
  21. --with-freetype-dir \
  22. --with-iconv-dir \
  23. --with-zlib-dir \
  24. --with-mcrypt \
  25. --enable-soap \
  26. --enable-gd-native-ttf \
  27. --enable-ftp \
  28. --enable-mbstring \
  29. --enable-exif \
  30. --disable-ipv6 \
  31. --with-pear \
  32. --with-curl \
  33. --with-openssl
  34.  
  35. error1:
  36. configure: error: xml2-config not found. Please check your libxml2 installation.
  37. [root@host129 php-5.6.]# yum -y install libxml2
  38. 已加载插件:fastestmirror, langpacks
  39. Loading mirror speeds from cached hostfile
  40. * base: mirrors..com
  41. * epel: mirrors.ustc.edu.cn
  42. * extras: mirrors..com
  43. * updates: mirrors..com
  44. 软件包 libxml2-2.9.-.el7_2..x86_64 已安装并且是最新版本
  45. 无须任何处理
  46. 解决:
  47. [root@host129 php-5.6.]# yum -y install libxml2-devel
  48.  
  49. error2:
  50. configure: error: Cannot find OpenSSL's <evp.h>
  51. 解决:
  52. [root@host129 php-5.6.]#yum -y install openssl.x86_64 openssl-devel.x86_64
  53.  
  54. error3:
  55. checking for T1lib support... no
  56. checking whether to enable truetype string function in GD... yes
  57. checking whether to enable JIS-mapped Japanese font support in GD... no
  58. If configure fails try --with-vpx-dir=<DIR>
  59. configure: error: jpeglib.h not found.
  60. 解决:
  61. [root@host129 php-5.6.]# yum -y install libjpeg libjpeg-devel
  62.  
  63. error4:
  64. configure: error: mcrypt.h not found. Please reinstall libmcrypt.
  65. 解决:
  66. [root@host129 php-5.6.]#yum -y install libmcrypt libmcrypt-devel
  67.  
  68. [root@host129 php-5.6.]#make install
  69. [root@host129 php-5.6.]# echo $?
  70.  
  71. [root@host129 php-5.6.]# cp php.ini-production /usr/local/php-fpm/etc/php.ini
  72. [root@host129 php-5.6.]# vim /usr/local/php-fpm/etc/php-fpm.conf
  73. [global]
  74. pid = /usr/local/php-fpm/var/run/php-fpm.pid
  75. error_log = /usr/local/php-fpm/var/log/php-fpm.log
  76. [www]
  77. listen = /tmp/php-fcgi.sock
  78. listen.mode =
  79. user = php-fpm
  80. group = php-fpm
  81. pm = dynamic
  82. pm.max_children =
  83. pm.start_servers =
  84. pm.min_spare_servers =
  85. pm.max_spare_servers =
  86. pm.max_requests =
  87. rlimit_files =
  88.  
  89. [root@host129 php-5.6.]# /usr/local/php-fpm/sbin/php-fpm -t
  90. [-Apr- ::] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
  91.  
  92. [root@host129 php-5.6.]# cp /usr/local/src/php-5.6./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  93. [root@host129 php-5.6.]# chmod /etc/init.d/php-fpm
  94. [root@host129 php-5.6.]# useradd -s /sbin/nologin php-fpm
  95. useradd:用户“php-fpm”已存在
  96. [root@host129 php-5.6.]# service php-fpm start
  97. Starting php-fpm done
  98. [root@host129 php-5.6.]# chkconfig php-fpm on
  99. [root@host129 php-5.6.]# ps aux |grep php-fpm

三、安装Nginx

  1. NGINX:
  2.  
  3. NGINX官网https://nginx.org/
  4. [root@host129 src]#cd /usr/local/src/
  5. [root@host129 src]# wget https://nginx.org/download/nginx-1.10.3.tar.gz
  6. [root@host129 src]# tar zxvf nginx-1.10..tar.gz
  7. [root@host129 src]# cd nginx-1.10./
  8. [root@host129 nginx-1.10.]# ./configure --prefix=/usr/local/nginx
  9. [root@host129 nginx-1.10.]# make & make install
  10.  
  11. 编写nginx启动脚本:
  12. [root@host129 nginx-1.10.]# vim /etc/init.d/nginx
  13.  
  14. #!/bin/bash
  15. # chkconfig: -
  16. # description: http service.
  17. # Source Function Library
  18. . /etc/init.d/functions
  19. # Nginx Settings
  20. NGINX_SBIN="/usr/local/nginx/sbin/nginx"
  21. NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
  22. NGINX_PID="/usr/local/nginx/logs/nginx.pid"
  23. RETVAL=
  24. prog="Nginx"
  25. start()
  26. {
  27. echo -n $"Starting $prog: "
  28. mkdir -p /dev/shm/nginx_temp
  29. daemon $NGINX_SBIN -c $NGINX_CONF
  30. RETVAL=$?
  31. echo
  32. return $RETVAL
  33. }
  34. stop()
  35. {
  36. echo -n $"Stopping $prog: "
  37. killproc -p $NGINX_PID $NGINX_SBIN -TERM
  38. rm -rf /dev/shm/nginx_temp
  39. RETVAL=$?
  40. echo
  41. return $RETVAL
  42. }
  43. reload()
  44. {
  45. echo -n $"Reloading $prog: "
  46. killproc -p $NGINX_PID $NGINX_SBIN -HUP
  47. RETVAL=$?
  48. echo
  49. return $RETVAL
  50. }
  51. restart()
  52. {
  53. stop
  54. start
  55. }
  56. configtest()
  57. {
  58. $NGINX_SBIN -c $NGINX_CONF -t
  59. return
  60. }
  61. case "$1" in
  62. start)
  63. start
  64. ;;
  65. stop)
  66. stop
  67. ;;
  68. reload)
  69. reload
  70. ;;
  71. restart)
  72. restart
  73. ;;
  74. configtest)
  75. configtest
  76. ;;
  77. *)
  78. echo $"Usage: $0 {start|stop|reload|restart|configtest}"
  79. RETVAL=
  80. esac
  81. exit $RETVAL
  82.  
  83. 保存以上脚本更改权限:
  84. [root@host129 nginx-1.10.]# chmod /etc/init.d/nginx
  85. 添加nginx服务项命令:
  86. [root@host129 nginx-1.10.]# chkconfig --add nginx
  87. 添加完设置启动项:
  88. [root@host129 nginx-1.10.]# chkconfig nginx on
  89.  
  90. 清空原配置文件:
  91. [root@host129 nginx-1.10.]# > /usr/local/nginx/conf/nginx.conf
  92.  
  93. 重新写入一下内容:
  94. [root@host129 nginx-1.10.]#vim /usr/local/nginx/conf/nginx.conf
  95.  
  96. user nobody nobody;
  97. worker_processes ;
  98. error_log /usr/local/nginx/logs/nginx_error.log crit;
  99. pid /usr/local/nginx/logs/nginx.pid;
  100. worker_rlimit_nofile ;
  101. events
  102. {
  103. use epoll;
  104. worker_connections ;
  105. }
  106. http
  107. {
  108. include mime.types;
  109. default_type application/octet-stream;
  110. server_names_hash_bucket_size ;
  111. server_names_hash_max_size ;
  112. log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
  113. ' $host "$request_uri" $status'
  114. ' "$http_referer" "$http_user_agent"';
  115. sendfile on;
  116. tcp_nopush on;
  117. keepalive_timeout ;
  118. client_header_timeout 3m;
  119. client_body_timeout 3m;
  120. send_timeout 3m;
  121. connection_pool_size ;
  122. client_header_buffer_size 1k;
  123. large_client_header_buffers 4k;
  124. request_pool_size 4k;
  125. output_buffers 32k;
  126. postpone_output ;
  127. client_max_body_size 10m;
  128. client_body_buffer_size 256k;
  129. client_body_temp_path /usr/local/nginx/client_body_temp;
  130. proxy_temp_path /usr/local/nginx/proxy_temp;
  131. fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
  132. fastcgi_intercept_errors on;
  133. tcp_nodelay on;
  134. gzip on;
  135. gzip_min_length 1k;
  136. gzip_buffers 8k;
  137. gzip_comp_level ;
  138. gzip_http_version 1.1;
  139. gzip_types text/plain application/x-javascript text/css text/htm
  140. application/xml;
  141. server
  142. {
  143. listen ;
  144. server_name localhost;
  145. index index.html index.htm index.php;
  146. root /usr/local/nginx/html;
  147. location ~ \.php$
  148. {
  149. include fastcgi_params;
  150. fastcgi_pass unix:/tmp/php-fcgi.sock;
  151. fastcgi_index index.php;
  152. fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
  153. }
  154. }
  155. }
  156.  
  157. 验证一nginx下配置文件:
  158. [root@host129 nginx-1.10.]# /usr/local/nginx/sbin/nginx -t
  159. 内容显示如下正常:
  160. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  161. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  162.  
  163. (查看一下:
  164. [root@host129 nginx-1.10.]#ps aux |grep httpd
  165. [root@host129 nginx-1.10.]#service stop httpd
  166. 也可以直接卸载:yum -y remove httpd )如果没下边启动报错可以不用做这一步
  167.  
  168. 启动Nginx
  169. [root@host129 nginx-1.10.]# service nginx start
  170. StartStarting nginx (via systemctl): Job for nginx.service failed because the control process exited with error code.
  171. See "systemctl status nginx.service" and "journalctl -xe" for details
  172.  
  173. 如果报以上错误:
  174. 通过查看日志:/var/log/messages这个日志
  175. [root@host129 nginx-1.10.]# less /var/log/messages
  176. Apr :: host129 nginx: Starting Nginx: nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
  177. Apr :: host129 nginx: nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
  178. Apr :: host129 nginx: nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
  179. Apr :: host129 nginx: nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
  180. Apr :: host129 nginx: nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
  181. Apr :: host129 nginx: nginx: [emerg] still could not bind()
  182. Apr :: host129 nginx: [失败]
  183. Apr :: host129 systemd: nginx.service: control process exited, code=exited status=
  184. Apr :: host129 systemd: Failed to start SYSV: http service..
  185. Apr :: host129 systemd: Unit nginx.service entered failed state.
  186. Apr :: host129 systemd: nginx.service failed.
  187.  
  188. 发现nginx端口被占用:
  189. [root@host129 nginx-1.10.]# ps aux |grep httpd
  190. root 0.0 0.3 ? Ss : : /usr/sbin/httpd -DFOREGROUND
  191. apache 0.0 0.2 ? S : : /usr/sbin/httpd -DFOREGROUND
  192. apache 0.0 0.2 ? S : : /usr/sbin/httpd -DFOREGROUND
  193. apache 0.0 0.2 ? S : : /usr/sbin/httpd -DFOREGROUND
  194. apache 0.0 0.2 ? S : : /usr/sbin/httpd -DFOREGROUND
  195. apache 0.0 0.2 ? S : : /usr/sbin/httpd -DFOREGROUND
  196. root 0.0 0.0 pts/ R+ : : grep --color=auto httpd
  197. [root@host129 nginx-1.10.]# service stop httpd
  198. The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
  199. [root@host129 nginx-1.10.]# systemctl stop httpd
  200. [root@host129 nginx-1.10.]# service nginx start
  201. Starting nginx (via systemctl): [ 确定 ]
  202.  
  203. 查看nginx启动进程:
  204. [root@host129 nginx-1.10.]# ps aux |grep nginx
  205. root 0.0 0.0 ? Ss : : nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  206. nobody 0.0 0.2 ? S : : nginx: worker process
  207. nobody 0.0 0.2 ? S : : nginx: worker process
  208. root 0.0 0.0 pts/ R+ : : grep --color=auto nginx
  209.  
  210. 验证php解析:
  211. [root@host129 nginx-1.10.]# vim /usr/local/nginx/html/.php
  212. <?php
  213. echo "test php scripts"
  214. ?>
  215. [root@host129 nginx-1.10.]# curl localhost/.php
  216. test php scripts
  217. 证明php解析正常

四、配置虚拟主机

  1. [root@host129 ~]# vim /usr/local/nginx/conf/nginx.conf
  2. 结束符之前:
  3. include vhost/*.conf;
  4. }
  5. [root@host129 ~]# mkdir /usr/local/nginx/conf/vhost
  6. [root@host129 ~]# cd /usr/local/nginx/conf/vhost/
  7. [root@host129 vhost]# vim default.conf
  8.  
  9. server
  10. {
  11. listen 80 default_server;
  12. server_name yanglt.com;
  13. index index.html index.htm index.php;
  14. root /data/nginx/default;
  15. }
  16.  
  17. [root@host129 vhost]# /usr/local/nginx/sbin/nginx -t
  18. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  19. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  20.  
  21. # /usr/local/nginx/sbin/nginx -s reload
  22. #makdir -r /data/nginx/default
  23. #echo "default_server" > /data/nginx/default/index.html
  24. [root@host129 nginx]# curl -x127.9.9.1:80 yanglt.com
  25. default_server
  26. [root@host129 nginx]# curl -x127.9.9.1:80 ssss.com
  27. default_server

【Linux运维】LNMP环境配置的更多相关文章

  1. linux运维之路配置网络

    前言裸机上装操作系统,想和物理机通信需要设置IP 开机以后: 第一步:setup命令  ——>  NetWork configguation  ---->Device configurat ...

  2. 网络配置——Linux运维基础

    今天把Linux的网络配置总结了一下,尽管并不难可是是个比較重要的基础.然后我也不知到自己以后是否会做运维,可是我知道自己比較喜欢刨根问底.还有就是我很珍惜我以前掌握过的这些运维的技能.今天突然间问自 ...

  3. 做linux运维工程师,必须要掌握以下几个工具

    linux系统如果是学习可以选用redhat或centos,特别是centos在企业中用得最多,当然还会有其它版本的,但学习者还是以这2个版本学习就行,因为这两个版本都是兄弟,没区别的,有空可以再研究 ...

  4. Linux运维入门到高级全套常用要点

    Linux运维入门到高级全套常用要点 目 录 1. Linux 入门篇................................................................. ...

  5. 要做linux运维工程师的朋友,必须要掌握以下几个工具才行 ...

    要做linux运维工程师的朋友,必须要掌握以下几个工具才行 ...  [复制链接]   发表于 2013-12-13 15:59 | 来自  51CTO网页 [只看他] 楼主           本人 ...

  6. Linux运维工程师入门的10大实用工具

    说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具. 我就大概列出这几方面,这样入门就基本没问题了. 工具如下: 1.Linux系统基础 这个不用说了,是基础中的基础,连这 ...

  7. Linux运维工程师入门须掌握的10个技术点

    本人是linux运维工程师,对这方面有点心得,现在我说说要掌握哪方面的工具吧 说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具. 我就大概列出这几方面,这样入门就基本没问 ...

  8. 详解linux运维工程师入门级必备技能

    详解linux运维工程师入门级必备技能 | 浏览:659 | 更新:2013-12-24 23:23 | 标签:linux it自动化运维就是要很方便的运用各种工具进行管理维护,有效的实施服务器保护 ...

  9. Linux 运维工程师的十个基本技能点

    本人是linux运维工程师,对这方面有点心得,现在我说说要掌握哪方面的工具吧. 说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具.我就大概列出这几方面,这样入门就基本没问 ...

  10. linux运维工程师

    本人是linux运维工程师,对这方面有点心得,现在我说说要掌握哪方面的工具吧说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具.我就大概列出这几方面,这样入门就基本没问题了 ...

随机推荐

  1. 原生ajax、XMLHttpRequest和FetchAPI简单描述

    什么是ajax ajax的出现,刚好解决了传统方法的缺陷.AJAX 是一种用于创建快速动态网页的技术.通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个 ...

  2. CodeForces - 598A Tricky Sum (数学,快速幂的运用)

    传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memor ...

  3. Mac改变系统截图存储路径

    时间:2018年9月13日 人物:同事和我 事情:看苹果秋季新品发布会,并且想要截图下来当时的新品介绍. 问题:系统的截图默认是存储在桌面,整理的时候,不是很方便. Mac截图快捷键: 截取选中区域: ...

  4. HTML表格和表单

    <table>格式: 注意:1. 合并单元格:COLSPAN(跨列)ROWSPAN(跨行) 2.cellspacing属性定义单元格之间的间距(以像素为单位). cellpadding属性 ...

  5. iOS | Swift图片剪切圆角

    我们在IOS开发中,时常需要将一些原本是方形的图片剪切成圆形或者边框是曲线的样子,表现得活泼生动一些. 注意:因为最近在尝试用Swiftl开发,所以这里的语言使用的就是Swift,OC的语法也是相近的 ...

  6. CSS实现表单

    效果图如下: HTML代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  7. 一个简易的android浏览器。求指教!

    开发android的浏览器很简单吧,不过这浏览器倒是很简易.下面每一处代码都备注上注解了!废话不多说,下面直接上代码! 运行后界面   主界面的代码 activity_main.xml布局 <L ...

  8. eclipse 右键没有Build Path

    如果Project Explorer右键没有build pathWindow ->show view 选择package explorer 参考https://blog.csdn.net/cod ...

  9. IO复用——select系统调用

    1.select函数 此函数用于在一段时间内,监听用户感兴趣的文件描述符上的可读.可写和异常等事件. #include<sys/select.h> int select(int nfds, ...

  10. python2.7入门---break语句&continue语句&pass空语句

        这篇文章记录的就是比较好玩的东西了,也是比较重要的.咱们先来看一下break语句.Python break语句,就像在C语言中,打破了最小封闭for或while循环.break语句用来终止循环 ...