您的位置:首页 > 其它

源码搭建LNMP

2016-12-02 18:26 162 查看
                              源码安装LNMP
                                       作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

前言:
  非常简单的一个平台LNMP,在生产实际环节中我们也经常用到!话不多说,开始享受我们的搭建过程吧!欢迎加入:高级运维工程师之路 598432640

一.源码安装nginx
1.安装依赖包

1 [root@yinzhengjie ~]# mkdir -pv /yinzhengjie/ && cd /yinzhengjie
2 [root@yinzhengjie yinzhengjie]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel


2.获取nginx软件包
[root@yinzhengjie ~]# wget http://nginx.org/download/nginx-1.9.15.tar.gz 我已经下载好了这个包:链接:http://pan.baidu.com/s/1o8lSow6 密码:i0tk

3.源码安装nginx

1 [root@yinzhengjie yinzhengjie]# useradd nginx -s /sbin/nologin -M
2 [root@yinzhengjie yinzhengjie]# tar -zxvf nginx-1.9.15.tar.gz
3 [root@yinzhengjie yinzhengjie]# cd nginx-1.9.15
4 root@yinzhengjie nginx-1.9.15]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
5 [root@yinzhengjie nginx-1.9.15]# make -j 4 && make install


4.编辑nginx配合文件,使其支持fast cgi功能

1 [root@yinzhengjie ~]# cd /usr/local/nginx/conf/
2 [root@yinzhengjie conf]# cp nginx.conf nginx.conf.`date +%F`
3 [root@yinzhengjie conf]# more nginx.conf
4 worker_processes 1;
5 events {
6     worker_connections 1024;
7 }
8 http {
9     include mime.types;
10     default_type application/octet-stream;
11     sendfile on;
12     keepalive_timeout 65;
13     gzip on;
14     server {
15         listen 80;
16         server_name localhost;
17         location / {
18                 root html;
19                 index index.html index.htm;
20         }
21         error_page 500 502 503 504 /50x.html;
22         location = /50x.html {
23                 root html;
24         }
25         location ~ \.php$ {
26                 root html;
27                 fastcgi_pass 127.0.0.1:9000;
28                 fastcgi_index index.php;
29                 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
30                 include fastcgi_params;
31         }
32
33     }
34 }
35 [root@yinzhengjie conf]#


5.编写Nginx启动脚本

1 [root@yinzhengjie conf]# cd /etc/init.d/
2 [root@yinzhengjie init.d]# more nginx
3 #!/bin/bash
4 #@author :yinzhengjie
5 #blog:http://www.cnblogs.com/yinzhengjie
6 #EMAIL:y1053419035@qq.com
7 #chkconfig: 2345 89 89
8
9 #Description:This is Nginx web script"
10
11 PID="/usr/local/nginx/logs/nginx.pid"
12
13 start(){
14         /usr/local/nginx/sbin/nginx
15         if [ $? -eq 0 ];then
16                 echo -en "Starting Nginx...\t\t\t["
17                 echo -en "\033[32;34mOK\033[0m"
18                 echo "]"
19         else
20                 echo "Starting Nginx Error"
21         fi
22 }
23
24 stop(){
25         /usr/local/nginx/sbin/nginx -s stop
26         if [ $? -eq 0 ];then
27                 echo -en "Stop Nginx...\t\t\t["
28                 echo -en "\033[32;34mOK\033[0m"
29                 echo "]"
30         else
31                 echo "Stop Nginx Error"
32         fi
33 }
34
35 status(){
36         if [ -f $PID ];then
37                 ID=$(cat $PID)
38                 echo "Ngix($ID) is running..."
39         else
40                 echo "Nginx is stop"
41         fi
42 }
43 case $1 in
44     start)
45         start
46         ;;
47     stop)
48         stop
49         ;;
50     restart)
51         stop
52         start
53         ;;
54     status)
55         status
56         ;;
57     *)
58         echo "Usage:$0 {start|stop|restart|status}"
59 esac
60 [root@yinzhengjie init.d]#


6.启动nginx

1 [root@yinzhengjie init.d]# cd
2 [root@yinzhengjie ~]#  iptables -I INPUT -p tcp --dport 80 -j ACCEPT
3 [root@yinzhengjie ~]# chmod +x /etc/init.d/nginx
4 [root@yinzhengjie ~]# chkconfig --add nginx
5 [root@yinzhengjie ~]# chkconfig nginx on
6 [root@yinzhengjie ~]# service nginx start
7 Starting Nginx...                       [OK]
8 [root@yinzhengjie ~]#


二.源码安装php
链接:http://pan.baidu.com/s/1hrRt88W 密码:9g0v
[root@yinzhengjie ~]# yum -y install lrzsz       #安装上传工具,利用上传工具将源码包上传到服务器

1.安装php

1 [root@yinzhengjie yinzhengjie]# pwd
2 /yinzhengjie
3 [root@yinzhengjie yinzhengjie]# tar -zxvf php-5.5.35.tar.gz
4 [root@yinzhengjie yinzhengjie]# cd php-5.5.35
5 [root@yinzhengjie php-5.5.35]# ./configure --prefix=/usr/local/product/php-5.5.35 --with-config-file-path=/usr/local/product/php-5.5.35/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
6 [root@yinzhengjie php-5.5.35]# make -j 4 && make install
7 [root@yinzhengjie php-5.5.35]# ln -s /usr/local/product/php-5.5.35 /usr/local/php
8 [root@yinzhengjie php-5.5.35]# cp php.ini-production /usr/local/php/etc/php.ini
9 [root@yinzhengjie php-5.5.35]# cd /usr/local/php/etc/
10 [root@yinzhengjie etc]#  cp php-fpm.conf.default php-fpm.conf
11 [root@yinzhengjie etc]# vim php.ini
12 需要修改以下几个参数:
13   max_execution_time = 300
14   post_max_size = 16M
15   max_input_time = 300
16   date.timezone = PRC


2.启动PHP服务

1 [root@yinzhengjie sbin]# cd /usr/local/php/sbin/
2 [root@yinzhengjie sbin]# ./php-fpm


3.检查php是否启动成功

1 [root@yinzhengjie sbin]# netstat -untalp | grep :9000
2 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 103859/php-fpm
3 [root@yinzhengjie sbin]#


三.源码安装mysql
1.创建mysql用户

1 [root@yinzhengjie ~]# groupadd mysql
2 [root@yinzhengjie ~]# mkdir -pv /yinzhengjie/data/mysql
3 mkdir: 已创建目录 "/yinzhengjie/data"
4 mkdir: 已创建目录 "/yinzhengjie/data/mysql"
5 [root@yinzhengjie ~]# useradd -r -g mysql -d /yinzhengjie/data/mysql/ -s /sbin/nologin mysql
6 [root@yinzhengjie ~]#


2.更换国内阿里云源

1 [root@yinzhengjie ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2 [root@yinzhengjie ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 3 [root@yinzhengjie ~]# yum clean all
4 [root@yinzhengjie ~]# yum makecache


3.获取mysql软件包
  这个包我也下载好了:链接:http://pan.baidu.com/s/1gfoOyIJ 密码:6qed

1 [root@yinzhengjie ~]# cd /yinzhengjie/
2 [root@yinzhengjie yinzhengjie]#  wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz[/code] 
4.安装依赖包
[root@yinzhengjie yinzhengjie]# yum -y install cmake gcc* ncurses-devel

5.源码安装mysql

1 [root@yinzhengjie yinzhengjie]# tar -zxvf mysql-5.5.49.tar.gz
2 [root@yinzhengjie yinzhengjie]# cd mysql-5.5.49
3 [root@yinzhengjie mysql-5.5.49]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/yinzhengjie/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci
4 [root@yinzhengjie mysql-5.5.49]# make -j 4 && make install
5 [root@yinzhengjie mysql-5.5.49]# chown -R mysql.mysql /usr/local/mysql
6 [root@yinzhengjie mysql-5.5.49]# cd /usr/local/mysql/support-files/


6.拷贝mysql配置文件

1 [root@yinzhengjie support-files]# cp my-medium.cnf /yinzhengjie/data/mysql/my.cnf
2 [root@yinzhengjie support-files]# cp mysql.server /etc/init.d/mysqld
3 [root@yinzhengjie  support-files]# chmod +x /etc/init.d/mysqld


7.初始化mysql

1 [root@yinzhengjie support-files]# cd /usr/local/mysql/scripts
2 [root@yinzhengjie scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/yinzhengjie/data/mysql/


8.修改mysql的数据目录

1 [root@yinzhengjie yinzhengjie]# cd /yinzhengjie/ && more /etc/my.cnf
2 [mysqld]
3 datadir=/yinzhengjie/data/mysql
4 socket=/var/lib/mysql/mysql.sock
5 user=mysql
6 # Disabling symbolic-links is recommended to prevent assorted security risks
7 symbolic-links=0
8 [mysqld_safe]
9 log-error=/var/log/mysqld.log
10 pid-file=/var/run/mysqld/mysqld.pid
11 [root@yinzhengjie yinzhengjie]# mkdir -pv /var/lib/mysql/ && ln -s /tmp/mysql.sock /var/lib/mysql/


9.启动mysql

[root@yinzhengjie yinzhengjie]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@yinzhengjie yinzhengjie]# ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
[root@yinzhengjie yinzhengjie]# service mysqld start
[root@yinzhengjie yinzhengjie]# mysqladmin -uroot password "yinzhengjie"


10.登陆数据库创建一个zabbix库

1 [root@yinzhengjie  yinzhengjie]# mysql -pyinzhengjie
2 mysql> create database zabbix default charset utf8;
3 mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';
4 mysql> flush privileges;
5 mysql> show databases;
6 mysql> quit


  致此:源码搭建LNMP平台完成~对了,如果你想给php写个启动脚本的话,可以参考我的Nginx启动脚本的哟~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: