centos7 LNMP 源码编译安装

  • 这篇笔记记录了在CentOS7.6中通过源码编译的方式安装nginx1.14,php7.2和mysql5.7的过程,以及使用systemctl管理服务,mysql5.7并未使用官网的二进制包,而是从源码开始自己编译的,要提醒的是mysql5.7编译环境至少需要1G内存,并且非常缓慢,本人实测1G内存很难成功编译,建议1G以上
1.安装nginx 安装依赖 yum -y install gcc gcc-c++ wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl openssl-devel 创建一个不能登录的nginx运行用户 groupadd www-data useradd -s /sbin/nologin -g www-data www-data 创建源码保存目录和运行时的临时文件夹,下载nginx源码,当前稳定版为nginx-1.14.2 mkdir -p /var/cache/nginx mkdir -p /usr/local/src/nginx cd /usr/local/src/nginx wget -c http://nginx.org/download/nginx-1.14.2.tar.gz 解压 tar -zxvf nginx-1.14.2.tar.gz cd /usr/local/src/nginx/nginx-1.14.2 编译前配置检查 ./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/local/nginx/sbin/nginx \ --conf-path=/usr/local/nginx/conf/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=www-data \ --group=www-data \ --with-pcre \ --with-http_v2_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-http_auth_request_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-http_v2_module \ --with-threads \ --with-stream \ --with-stream_ssl_module 配置检查完毕,已经创建了Makefile creating objs/Makefile Configuration summary + using threads + using system PCRE library + using system OpenSSL library + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/var/run/nginx.pid" nginx error log file: "/var/log/nginx/error.log" nginx http access log file: "/var/log/nginx/access.log" nginx http client request body temporary files: "/var/cache/nginx/client_temp" nginx http proxy temporary files: "/var/cache/nginx/proxy_temp" nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp" nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp" nginx http scgi temporary files: "/var/cache/nginx/scgi_temp" 编译,安装 make make install 修改配置 nginx详细配置请移步(nginx的configure参数,配置文件,虚拟主机配置,信号控制) vim /usr/local/nginx/conf/nginx.conf user www-data; pid /var/run/nginx.pid; 启动nginx /usr/local/nginx/sbin/nginx 查看进程 ps aux|grep nginx 杀掉进程 pkill -9 nginx 配置服务 vim /usr/lib/systemd/system/nginx.service 输入如下配置 [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID ExecStartPost=/bin/sleep 0.1 [Install] WantedBy=multi-user.target #注意:如果你是单核服务器,需要加ExecStartPost=/bin/sleep 0.1 #否则在执行systemctl start nginx之后,在执行systemctl status nginx时 #会出现systemd[1]: Failed to read PID from file /var/run/nginx.pid: Invalid argument #这是因为nginx还未启动完成,systemctl就去寻找pid进程文件了,这是一个已知的bug #地址https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864 重新载入 systemd systemctl daemon-reload 开启开机启动 systemctl enable nginx.service Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service. 启动和查看nginx状态 systemctl start nginx systemctl status nginx ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since 五 2019-01-04 18:24:18 CST; 9min ago Docs: http://nginx.org/en/docs/ Process: 75573 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS) Process: 75576 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS) Main PID: 75577 (nginx) CGroup: /system.slice/nginx.service ├─75577 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf └─75578 nginx: worker process 1月 04 18:24:18 jmsiteos7 systemd[1]: Stopping nginx - high performance web server... 1月 04 18:24:18 jmsiteos7 systemd[1]: Stopped nginx - high performance web server. 1月 04 18:24:18 jmsiteos7 systemd[1]: Starting nginx - high performance web server... 1月 04 18:24:18 jmsiteos7 systemd[1]: Started nginx - high performance web server. 2.安装mysql 注:MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具。因此,我们首先要在系统中源码编译安装cmake工具。 安装依赖 yum install -y cmake gcc-c++ bison bison-devel ncurses-devel perl-Data-Dumper boost boost-doc boost-devel 创建mysql用户和用户组 groupadd mysql useradd -g mysql mysql 创建源码存放目录,下载,解压 mkdir -p /usr/local/src/mysql cd /usr/local/src/mysql wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz tar -zxvf mysql-boost-5.7.20.tar.gz cd mysql-5.7.20 创建相应目录并授权 mkdir -p /usr/local/mysql/data chown -R mysql:mysql /usr/local/mysql/ touch /var/log/mysql.log chown -R mysql:mysql /var/log/mysql.log mkdir -p /var/lib/mysql chown -R mysql:mysql /var/lib/mysql mkdir -p /var/run/mysqld chown -R mysql:mysql /var/run/mysqld 配置检查 cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DMYSQL_USER=mysql \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_unicode_ci \ -DWITH_DEBUG=0 \ -DMYSQL_MAINTAINER_MODE=0 \ -DWITH_SYSTEMD=1 \ -DWITH_BOOST=boost \ -DWITH_SSL:STRING=bundled \ -DWITH_ZLIB:STRING=bundled 编译,安装 make make install 修改mysql配置 vim /etc/my.cnf 如下设置 [mysql] default-character-set=utf8 socket=/var/lib/mysql/mysql.sock [mysqld] init-connect = 'SET NAMES utf8' character-set-server = utf8 basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/var/lib/mysql/mysql.sock user = mysql explicit_defaults_for_timestamp=true bind-address = 0.0.0.0 server-id = 1 log_error=/var/log/mysql.log # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid 加入环境变量 vim /etc/profile 尾部加入下面两行 PATH=$PATH:/usr/local/mysql/bin/ export PATH 执行source使环境变量立即生效 source /etc/profile 初始化数据库,安装密钥 mysqld --defaults-file=/etc/my.cnf --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql mysql_ssl_rsa_setup #–initialize-insecure不生成随机密码 #–initialize生成随机密码 设置开机启动 cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system 重新载入 systemd systemctl daemon-reload 开机启动 systemctl enable mysqld.service systemctl start mysqld.service [root@jmsiteos7 mysql-5.7.20]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 五 2019-01-04 15:36:52 CST; 3s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 30737 ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 30719 ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 30740 (mysqld) CGroup: /system.slice/mysqld.service └─30740 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 1月 04 15:36:51 jmsiteos7 systemd[1]: Starting MySQL Server... 1月 04 15:36:52 jmsiteos7 systemd[1]: Started MySQL Server. 设置密码(如果初始化参数是–initialize,这步跳过) mysql_secure_installation 登录mysql [root@jmsiteos7 ~]# mysql -uroot -p mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> set password for root@localhost = password('yourpassword'); mysql> flush privileges; mysql> quit; Bye 3.安装php 安装依赖 yum install libxml2 libxml2-devel curl-devel openjpeg openjpeg-devel openjpeg-libs libjpeg libjpeg-devel libpng freetype libpng-devel freetype-devel openssl openssl-devel 创建源码保存目录,下载,解压 mkdir -p /usr/local/src/php72 cd /usr/local/src/php72 wget -c http://cn2.php.net/get/php-7.2.13.tar.gz tar -xzvf php-7.2.13.tar.gz cd php-7.2.13 配置检查 ./configure --prefix=/usr/local/php72 \ --with-config-file-path=/usr/local/php72/etc \ --with-config-file-scan-dir=/usr/local/php72/etc/php.d \ --with-mhash \ --disable-debug \ --disable-rpath \ --enable-mysqlnd \ --with-mysqli \ --with-pdo-mysql \ --enable-fpm \ --with-fpm-user=www-data \ --with-fpm-group=www-data \ --with-gd \ --with-iconv \ --with-zlib \ --enable-bcmath \ --enable-xml \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --enable-mbregex \ --enable-mbstring \ --enable-ftp \ --with-openssl \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --without-pear \ --with-gettext \ --enable-session \ --with-curl \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir 编译,安装 make -j4 make install 设置环境变量 vim /etc/profile 文件末尾加入如下两行代码 PATH=$PATH:/usr/local/php72/bin/:/usr/local/php72/sbin/ export PATH 使之立即生效 source /etc/profile 测试一下 [root@jmsiteos7 php-7.2.13]# php -v PHP 7.2.13 (cli) (built: Jan 4 2019 17:35:17) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies 设置php.ini和php-fpm.conf,www.conf 进入源码目录 cd /usr/local/src/php72/php-7.2.13 复制示例配置 cp php.ini-development /usr/local/php72/etc/php.ini #或 cp php.ini-production /usr/local/php72/etc/php.ini 进入php.ini目录 cd /usr/local/php72/etc 打开配置文件 vim /usr/local/php72/etc/php.ini 更改pdo_mysql.default_socket为上面安装mysql时.sock设定的位置 pdo_mysql.default_socket = /var/lib/mysql/mysql.sock 如果不设置,php通过pdo连接mysql时会报SQLSTATE[HY000] [2002] No such file or directory 复制fpm示例配置 cp php-fpm.conf.default php-fpm.conf 进入php-fpm.d目录 cd /usr/local/php72/etc/php-fpm.d 复制www.conf cp www.conf.default www.conf 设置php-fpm开机启动 cp /usr/local/src/php72/php-7.2.13/sapi/fpm/php-fpm.service /usr/lib/systemd/system/ 重新载入 systemd systemctl daemon-reload 启用开机启动 systemctl enable php-fpm Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service. 启动php-fpm systemctl start php-fpm 查看状态 [root@jmsiteos7 php-fpm.d]# systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since 五 2019-01-04 17:55:16 CST; 5s ago Main PID: 70669 (php-fpm) CGroup: /system.slice/php-fpm.service ├─70669 php-fpm: master process (/usr/local/php72/etc/php-fpm.conf) ├─70670 php-fpm: pool www └─70671 php-fpm: pool www 1月 04 17:55:16 jmsiteos7 systemd[1]: Started The PHP FastCGI Process Manager. 4.验证安装的nginx,php,mysql 编辑nginx配置文件 vim /usr/local/nginx/conf/nginx.conf #更改运行用户 user www-data; #编辑server段,默认文件添加index.php location / { root html; index index.php index.html index.htm; } #匹配php的配置块取消注释并更改/scripts为$document_root location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } 保存并退出,重启nginx systemctl restart nginx nginx默认的web目录下新建index.php vim /usr/local/nginx/html/index.php 输入如下php代码 <?php $dbms='mysql'; //数据库类型 $host='localhost'; //数据库主机名 $dbName='mysql'; //使用的数据库 $user='root'; //数据库连接用户名 $pass=''; //对应的密码 $dsn="$dbms:host=$host;dbname=$dbName"; try { $dbh = new PDO($dsn, $user, $pass); //初始化一个PDO对象 echo "连接成功<br/>"; foreach ($dbh->query('SELECT db from db') as $row) { print_r($row); } $dbh = null; } catch (PDOException $e) { die ("Error!: " . $e->getMessage() . "<br/>"); } ?> 浏览器访问你的站点  

原文地址:https://www.cnblogs.com/kevinleerunqing/p/12034284.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


本篇内容介绍了“LNMP服务器环境配置实例分析”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情...
本篇内容主要讲解“OneinStack如何一键安装LNMP”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“OneinStack如何...
小编给大家分享一下如何解决LNMP安装composer install时出现Warning: putenv()问题,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅...
1.源码安装mysql鉴于前边的文章已经详细说过mysql的源码安装可以点击基于LAMP的Discuz论坛的实现(源码安装)自行查看这里为了节省时间用一个shell脚本进行mysql的源码安装用到的mysql依然是5.6.46没有源码包的同学可以点击【mysql-5.6.46.tar.gz提取码:nli5】进行下载
Linux是非常热门的技术,也是当下非常受欢迎的操作系统,具有独特的优势所在,广受大家的喜欢和追捧,今天为大家分享一下几款常用的Linux系统面板,希望对你有所帮助。1、宝塔面板:是一款使用方便、功能强大而且终身免费的服务器管理软件,支持Linux以及Windows系统,一键配置LAMP/LNMP
██【電:131.乀.1418.乀.6667】【薇q:9788.乀.9181】██柬埔寨东方明珠开户目录LAMP1.安装Mariadb2.安装PHP3.测试php和apache的协同4.修改MariaDB数据库配置5.测试数据库连接LNMP(未完待续)LAMP1.安装Mariadb在RaspberryPi中,MySQL无法安装,会自动建议安装Maria
关闭防火墙安装依赖包上传源码包解压源码包,安装nginx启动nginx安装mysql和PHP相关服务修改nginx配置文件,nginx和PHP进行整合重新加载nginx服务启动php-fpm书写PHP测试页测试网页 
一.lnmp的搭建1.准备一台纯净版的虚拟机2.下载Lnmp一键安装包命令:wget http://soft.vpser.net/lnmp/lnmp1.5-full.tar.gz【安装完整版的-推荐1.5版本】也可以本地下载好,通过rz上传:http://soft.vpser.net/lnmp/lnmp1.5-full.tar.gz3.开始安装命令:cdlnmp1.5-full 
1.LNMP理论fastcgi的主要优点:把动态语言和http服务器分离开来,使nginx可以处理静态请求和向后转发动态请求,而php/php-fpm服务器转移解析PHP动态请求使用fastcgi的原因:Nginx不支持对外部动态程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。
keepalived高可用keepalived注意:任何软件都可以使用keepalived来做高可用keepalived如何实现高可用VRRP:虚拟路由冗余协议比如公司的网络是通过网关进行上网的,那么如果该路由器故障了,网关无法转发报文了,此时所有人都无法上网了,怎么办?通常做法是给路由器增加一台备节点,但是问
通过阿里云的服务器搭建lnmp架构以及部署wordpress个人博客,连接上域名所遇到的问题及解决办法注释:操作系统centos7.9第一步:购买阿里云ecs服务器,选择系统及其他硬件,下面是我自己购买的配置,可以参考(注意操作系统我购买的时候选错了,后来换成了centos7.9)然后在阿里云“云服
文章目录1.首先了解编译安装和yum安装的区别。2.yum安装准备工作---切换阿里云yum源3.编译安装lnmp**很不建议使用编译安装,麻烦且容易报错。**4.yum安装lnmp**可以先执行一下yumupdate**5.lnmp一键安装[参考网站](https://lnmp.org/)**不喜欢这种方式,所以没测试
电影院系统解压登录mysql创建电影院系统使用的数据库授权账户skyuc访问数据库讲系统部署到www.benet.com网站根目录下mv/usr/src/SKYUC.v3.4.2.SOURCE/wwwroot/*/var/www/benetcom/设置网站根目录所有者和权限客户机测试论坛系统部署解压复制文件到网站根目
下载:​ https://www.php.net/downloads​ https://www.php.net/distributions/php-8.0.6.tar.gz编译安装php:①安装依赖:yum-yinstalllibxml2-develsqlite-develbzip2-devellibcurl-devellibpng-devellibjpeg-develfreetype-devellibicu-develoniguruma-devellibxs
树莓派LNMP关键词:raspberrywebphpdnsmysq1LNMP、LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写,分别指Linux、Nginx/Apache、MySQL和PHP。这里演示如何在树莓派上搭建LNMP环境并配置多个站点。主要内容:树莓派安装nginx树莓派安装ph
官网:http://kodcloud.com/1、准备MySQL数据库 [root@cent8_yzl_20~]#yuminstall-ymysql-server[root@cent8_yzl_20~]#systemctlenable--nowmysqld[root@cent8_yzl_20~]#mysqlmysql>createdatabasekodbox;mysql>createuserkodbox@'10.0.0.
环境应用IP操作系统nginx192.168.122.131centos8mysql192.168.122.132centos8php192.168.122.133centos8准备工作//关闭防火墙#systemctldisable--nowfirewalld#setenforce0#vim/etc/selinux/configSELINUX=disabled安装nginx//安装依
1.购买vps或者外国云主机2.搭建ss服务端3.客户端配置服务端信息,即可。不废话,开始教程:ss-panel-v3简介ss-panel是一套功能齐全的shadowsocks用户管理面板,它可以实现用户注册、用户管理、流量控制、签到、添加多节点、充值购买、邀请返利等诸多功能,是目前网络上使用最广泛的一
LNMP架构数据迁移至NFS第一步:先将原有目录中数据移出数据存储到本地什么位置,获取方法1.通过网站页面右键点击,获取资源地址信息2.find命令利用-mmin53.利用inotify服务监控目录数据变化[root@web01wp-content]#cd/applicationginx/html/blog/wp-content/uploads[root@we
一 点睛业务上线之前最关键的一项任务便是环境部署,往往一个业务涉及多种应用环境,比如Web、DB、PROXY、CACHE等,本示例通过env.roledefs定义不同主机角色,再使用“@roles('webservers')”修饰符绑定到对应的任务函数,实现不同角色主机的部署差异。二 代码#coding=utf-8#!/usr