当前位置: 首页 > Linux

Linux运维:CentOS7安装LNMP(nginx1.14.2、mariadb10.3.13、php7.3.3)

时间:2023-04-06 21:06:43 Linux

序系统环境[root@lnmpmysql]#cat/etc/redhat-releaseCentOSLinuxrelease7.3.1611(Core)[root@lnmpmysql]#uname-r3.10.0-514.el7.x86_64官方下载地址mariadb数据库phpngixninstallmariadb10.3.131。下载mariadb二进制包,因为源码包编译时间太长。二进制包$wgethttps://mirrors.shu.edu.cn/mariadb//mariadb-10.3.13/bintar-linux-x86_64/mariadb-10.3.13-linux-x86_64.tar.gz2。解压$tar-zxvfmariadb-10.3.13-linux-x86_64.tar.gz3。将解压后的二进制包放在软件目录下。这里我习惯放在/usr/local下,重命名为mysql$mvmariadb-10.3.13-linux-x86_64/usr/local/mysql4。创建数据存储目录和管理用户mysql$groupaddmysql$useradd-s/sbin/nologin-Mmysql$cd/usr/local/mysql$chown-Rmysql:mysql.5.初始化$./scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data如果这一步报错:/usr/local/mariadb/bin/mysqld:加载共享库时出错:libaio.so.1:无法打开共享对象文件:没有这样的文件或目录解决方案:yuminstall-ylibaio-devel6。检查是否安装成功并初始化使用$ech$?命令后查看返回结果是否为0,0表示成功,不为0表示失败7、复制启动脚本,使用chkconfig工具管理$cd/usr/local/mysql$cpsupport-files/mysql。server/etc/init.d/mysqld#定义启动脚本内容,修改datadir和basedir$vim/etc/init.d/mysqld#修改basedir=/usr/local/mysql#软件目录datadir==/usr/local/mysql/data#存放数据目录#修改后设置开机自启动$chkconfig--addmysqld$chkconfigmysqldon8.设置mariadb配置文件/etc/my.cnf$vim/etc/my.cnf#修改配置内容saveexitfordatadir=/usr/local/mysql/datasocket=/tmp/mysql.socklog-error=/usr/local/mysql/data/mariadb.logpid-file=/usr/local/mysql/data/mariadb.pid。9.启动mariadb服务$/etc/init.d/mysqldstart#启动mariadb10。查看端口进程[root@lnmpmysql]$netstat-lntp|grepmysqltcp600:::3306:::*听4225/mysqld[root@lnmpmysql]$psaux|grepmysqlroot41400.00.01154361756?S13:310:00/bin/sh/usr/local/mysql/bin/mysqld_safe--datadir=/usr/local/mysql/data--pid-file=/usr/local/mysql/data/lnmp。pidmysql42250.04.8171371690736?Sl13:310:00/usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data--plugin-dir=/usr/local/mysql/lib/plugin--user=mysql--log-error=/usr/local/mysql/data/mariadb.log--pid-file=/usr/local/mysql/data/lnmp.pid--socket=/tmp/mysql.sockroot42800.00.0112728964pts/1S+13:430:00grep--color=automysql11.进入mariadb数据库$/usr/local/mysql/bin/mysql欢迎使用MariaDB监视器。命令以;结尾或\g。你的玛丽亚数据库连接ID为10服务器版本:10.3.13-MariaDBMariaDB服务器版权所有(c)2000、2018、Oracle、MariaDBCorporationAb等。输入“帮助;”或'\h'寻求帮助。输入'\c'清除当前输入语句。MariaDB[(none)]>12.设置软连接$ln-s/usr/local/mysql/bin/mysql/usr/bin$ln-s/usr/local/mysql/bin/mysqladmin/usr/bin13.设置root密码$mysqladmin-uroot-p'!@#123qwe'14。root用户登录mysql[root@lnmpmysql]#mysql-uroot-p输入密码:欢迎使用MariaDB监视器。命令以;结尾或\g。您的MariaDB连接ID是16Server版本:10.3.13-MariaDBMariaDBServerCopyright(c)2000,2018,Oracle,MariaDBCorporationAbandothers.Type'help;'或'\h'寻求帮助。键入'\c'清除当前输入语句。MariaDB[(none)]>此时,mariadb已安装,php7.3.31已安装。下载包下载地址:http://php.net/get/php-7.3.3.tar.bz2/from/a/mirror选择中文镜像站点下载,或者复制链接地址wget下载。这里我先下载到我的window,再上传到linux。2、解压$tar-jxvfphp-7.3.3.tar.bz2#如果没有安装bzip2工具,会报错$yuminstall-ybzip23。安装依赖包$yuminstall-ygcclibxml2-develzlib-developenssl-develbzip2-devellibjpeg-devellibpng-develepel-releaselibmcrypt-develcurl-develfreetype-devel4。编译参数$./configure--prefix=/usr/local/php-fpm--with-config-file-path=/usr/local/php/etc--enable-fpm--with-fpm-user=php-fpm--with-fpm-group=php-fpm--with-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-mysql-sock=/tmp/mysql.sock--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir--with-freetype-dir--with-iconv-dir--with-zlib-dir--with-mcrypt--enable-soap--enable-gd-native-ttf--enable-ftp--enable-mbstring--enable-exif--with-pear--with-curl--with-openssl5。安装make&&makeinstall6。复制配置文件$cp/usr/local/src/php-7.3.3/php.ini-development/usr/local/php-fpm/etc/php.ini$cp/usr/local/php-fpm/etc/php-fpm.conf.default/usr/local/php-fpm/etc/php-fpm.conf7。配置启动脚本设置启动$cp/usr/local/src/php-7.3.3/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm$chmod+xphp-fpm$chkconfig--addphp-fpm$chkconfigphp-fomon8.创建用户,配置pool$useraddphp-fpm$cp/usr/local/php-fpm/etc/php-fpm.d/www.conf.default/usr/local/php-fpm/etc/php-fpm.d/www.conf9.启动服务,查看进程[root@lnmp~]$servicephp-fpmstartStartingphp-fpmdone[root@lnmp~]$psaux|grepphp-fpmroot187470.00.31159926284?Ss13:270:00php-fpm:主进程(/usr/local/php-fpm/etc/php-fpm.conf)php-fpm187480.00.31159925836?S13:270:00php-fpm:池wwwphp-fpm187490.00.31159925836?S13:270:00php-fpm:池wwwroot187510.00.0112724988pts/0S+13:270:00grep--color=autophp-fpm[root@lnmp~]$netstat-lntp|grepphp-fpmtcp00127.0.0.1:90000.0.0.0:*LISTEN18747/php-fpm:安装了mastphp编译安装nginx1.14.21。下载包$cd/usr/local/src$wgethttp://nginx.org/download/nginx-1.14.2.tar.gz2。解压$tar-zxvfnginx-1.14.2。tar.gz3.编译安装$cdnginx-1.14.2$./configure--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module$make&&makeinstall4.添加nginx启动脚本$vim/etc/init.d/nginx内容如下:#!/bin/bash#chkconfig:-3021#description:httpservice.#源函数库。/etc/init.d/functions#Nginx设置NGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"RETVAL=0prog="Nginx"start(){echo-n$"启动$prog:"mkdir-p/dev/shm/nginx_tempdaemon$NGINX_SBIN-c$NGINX_CONFRETVAL=$?echoreturn$RETVAL}stop(){echo-n$"Stopping$prog:"killproc-p$NGINX_PID$NGINX_SBIN-TERMrm-rf/dev/shm/nginx_tempRETVAL=$?echoreturn$RETVAL}reload(){echo-n$"正在重新加载$prog:"killproc-p$NGINX_PID$NGINX_SBIN-HUPRETVAL=$?echoreturn$RETVAL}restart(){stopstart}configtest(){$NGINX_SBIN-c$NGINX_CONF-treturn0}case"$1"instart)start;;停止)停止;;重新加载)重新加载;;重新启动)重新启动;;配置测试)配置测试;;*)echo$"Usage:$0{start|stop|reload|restart|configtest}"RETVAL=1esacexit$RETVAL5。设置nginx启动$chmod+x/etc/init.d/nginx$chkconfig--addnginx$chkconfignginxon6。启动nignx,查看进程端口[root@lnmpnginx-1.14.2]$/etc/init.d/nginxstartStartingnginx(viasystemctl):[OK][root@lnmpnginx-1.14.2]$psaux|grepnginxroot214860.00.0459481120?Ss13:500:00nginx:主进程/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.confnobody214870.00.1463841900?S13:500:00nginx:workerprocessroot214890.00.0112724988点/0S+13:500:00grep--color=autonginx[root@lnmpnginx-1.14.2]$netstat-lntp|grepnginxtcp000.0.0.0:800.0.0.0:*LISTEN21486/nginx:master到目前为止nginx已安装