源码编译LNMP环境

yum -y install epel-release

安装依赖
yum -y install make gcc gcc-c++ bison-devel ncurses-devel perl-Data-Dumper boost boost-doc boost-devel cmake
下载包并安装
wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.22.tar.gz
tar -zxvf mysql-boost-5.7.22.tar.gz && cd mysql-5.7.22
mkdir -p /usr/local/mysql/{mydata,conf}
chown -R mysql.mysql /usr/local/mysql*

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
 -DMYSQL_DATADIR=/usr/local/mysql/mydata  \
 -DSYSCONFDIR=/usr/local/mysql/conf \
 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all \
 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \
 -DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 \
 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled \
 -DWITH_SYSTEMD=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost
注意:---------------------------------------------------------------
-DWITH_SYSTEMD=1        ------是否支持systemd方式管理MySQL
-DDOWNLOAD_BOOST=1      ------自动下载boost支持
-DWITH_BOOST=./boost    ------本地boost目录
为了简化本地连接MySQL,提供一种封装形式的TCP/IP协议。
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock

编译
make && make install
初始化
/usr/local/mysql/bin/mysqld --initialize-insecure  --user=mysql --datadir=/usr/local/mysql/mydata --basedir=/usr/local/mysql
注意:初始化后密码为空,在初始化完毕后会有提示
修改配置文件:vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/mydata
socket=/usr/local/mysql/mysql.sock
log_error=/var/log/mysql.log
user=mysql
[client]
socket=/usr/local/mysql/mysql.sock

创建日志文件
touch /var/log/mysql.log && chown -R mysql.mysql /var/log/mysql.log
更新启动脚本
cd /usr/local/mysql/support-files && sed -i 's/mysqld_safe/mysqld/g' mysql.server
cp mysql.server /etc/rc.d/init.d/mysqld
配置systemd管理
vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

systemd管理启动
systemctl  start/stop/restart/status   mysqld
配置环境变量
echo 'export PATH=/usr/local/mysql/bin:$PATH'>>/etc/profile
source /etc/profile
密码配置
mysqladmin password '123456'        -----第一次改密码使用方法,密码为"123456"
验证
netstat -anpt|grep :3306
cd ~

安装PHP
useradd -s /sbin/nologin -u 122 -M nginx
安装依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt-devel libicu-devel

下载源码包
wget -c http://cn2.php.net/distributions/php-7.1.5.tar.gz
tar zxf php-7.1.5.tar.gz && cd php-7.1.5/
./configure --prefix=/usr/local/php-7.1.5 \
--with-config-file-path=/usr/local/php-7.1.5/etc \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli --enable-fpm --with-fpm-user=nobody \
--with-fpm-group=nobody --with-pdo-mysql=mysqlnd \
--with-iconv-dir --with-freetype-dir --with-jpeg-dir \
--with-png-dir --with-zlib \
--with-libxml-dir --enable-xml --enable-bcmath \
--enable-shmop --enable-sysvsem \
--enable-inline-optimization --with-curl \
--enable-mbregex --enable-mbstring \
--enable-intl --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 --enable-opcache --with-xsl

make && make install
ln -s /usr/local/php-7.1.5 /usr/local/php
cp php.ini-development /usr/local/php/lib/php.ini
sed -i "mysqli.default_socket =/mysqli.default_socket = \/usr\/lcoal\/mysql\/mysql.sock/" /usr/local/php/lib/php.ini
sed -i ";date.timezone =/date.timezone = Asia/Shanghai" /usr/local/php/lib/php.ini
sed -i "pdo_mysql.default_socket=/pdo_mysql.default_socket=\/usr\/local\/mysql\/mysql.sock" /usr/local/php/lib/php.ini
验证安装的模块
/usr/local/php/bin/php -m
配置fpm模块
cd /usr/local/php/etc/ && cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/ && cp www.conf.default www.conf
sed -i "s/;pid = run\/php-fpm.pid/pid = run\/php-fpm.pid/" /usr/local/php/etc/php-fpm.conf
配置systemd管理
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start php-fpm && systemctl enable php-fpm
验证:netstat -anpt|grep :9000
cd ~

安装nginx
安装依赖
yum -y install pcre* openssl-devel
解压源码包
wget -c http://nginx.org/download/nginx-1.14.2.tar.gz
tar zxf nginx-1.14.2.tar.gz && cd nginx-1.14.2
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module --with-http_stub_status_module \
--with-http_stub_status_module --with-pcre

make && make install
检测是否安装成功
/usr/local/nginx/sbin/nginx -t
备份并修改配置文件
cd /usr/local/nginx/conf/ && cp nginx.conf{,.bak}
cat nginx.conf|grep -v ^#|grep -v "    #"|grep -v ^$
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  172.16.186.142;
        location / {
            root   html;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           html/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}



加入systemd管理
vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx server daemon
Documentation=man:nginx(8)
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target


systemctl daemon-reload
systemctl start nginx && systemctl enable nginx
netstat -anpt|grep :80

默认站点目录:/usr/local/nginx/html
测试文件添加:
mkdir -p /usr/local/nginx/html/www
echo '<?php  phpinfo(); ?>'>>/usr/local/nginx/html/www/phpinfo.php

访问:http://172.16.186.141/phpinfo.php

测试MySQL文件
vim /usr/local/nginx/html/www/mysql.php
<?php
$link=mysqli_connect('localhost','root','123456');
if($link) echo "<h1>Database connection successful</h1>";
else echo "Fail!!";
?>

访问:http://172.16.186.141/mysql.php

posted @ 2020-11-25 17:37  Linux大魔王  阅读(104)  评论(0编辑  收藏  举报