码迷,mamicode.com
首页 > 系统相关 > 详细

LINUX——lnmp架构的搭建,与lamp架构类似

时间:2018-09-04 20:52:15      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:sed   php程序   sha   support   mat   params   启动脚本   c++   adb   

关闭防火墙

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# sed -ri ‘s/(SELINUX=).*/\1disabled/g‘ /etc/selinux/config
[root@localhost ~]# setenforce 0

配置安装163的源

[root@localhost ~]# cd /etc/yum.repos.d/
//创建备份目录
[root@localhost yum.repos.d]# mkdir /etc/repo-bf
//将原yum仓库的文件备份到repo-bf
[root@localhost yum.repos.d]# mv * /etc/repo-bf
//下载163的源到yum仓库
[root@localhost yum.repos.d]# curl -o 163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
//将改为版本的7
[root@localhost yum.repos.d]# sed -i ‘s/\$releasever/7/g‘ /etc/yum.repos.d/163.repo
[root@localhost yum.repos.d]# sed -i ‘s/enabled=0/enabled=1/g‘ /etc/yum.repos.d/163.repo
//自动配置yum的软件仓库,也可以自己配置
[root@localhost yum.repos.d]# yum -y install epel-release
[root@localhost yum.repos.d]# yum clean all
//安装编译环境
[root@localhost yum.repos.d]# yum -y install gcc gcc-c++
[root@localhost yum.repos.d]# yum -y install wget

安装依赖包

//创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx 

//安装编译环境
[root@localhost ~]# yum -y groups list
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel

文件中的包,如果如果在xshell中无法下载,可以先下载然后传入

//创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx 
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx 

//下载nginx,编译安装
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://64.123.28.133/files/21490000000827F6/nginx.org/download/nginx-1.14.0.tar.gz
[root@localhost src]# tar xf nginx-1.14.0.tar.gz 
[root@localhost src]# cd nginx-1.14.0
[root@localhost nginx-1.14.0]# yum -y install gcc gcc-c++
[root@localhost nginx-1.14.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

[root@localhost nginx-1.14.0]# make -j 4 && make install

//设置环境变量

[root@localhost nginx-1.14.0]# echo ‘export PATH=/usr/local/nginx/sbin:$PATH‘ > /etc/profile.d/nginx.sh
[root@localhost nginx-1.14.0]# . /etc/profile.d/nginx.sh

//启动
[root@localhost nginx-1.14.0]# nginx

技术分享图片
2.安装mysql

//安装依赖包
[root@guohui ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
创建用户和组
[root@guohui ~]# groupadd -r -g 306 mysql
[root@guohui ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql

下载二进制格式的mysql软件包

[root@localhost ~]# cd /usr/src/
[root@guohui src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
解压软件至/usr/local/
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz  nginx-1.14.0  nginx-1.14.0.tar.gz

[root@localhost src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls  /usr/local/
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.22-linux-glibc2.12-x86_64  nginx  sbin  share  src

[root@localhost src]# cd  /usr/local/
[root@localhost local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.22-linux-glibc2.12-x86_64/"

//修改属主
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 8月  24 16:13 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/

//设置环境变量
[root@localhost local]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

//建立数据存放目录
[root@localhost local]# cd /usr/local/mysql
[root@localhost mysql]# mkdir /opt/data
[root@localhost mysql]# chown -R mysql.mysql /opt/data/

//初始化数据库,最后生成的是一个临时密码
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2018-08-24T08:20:10.891585Z 1 [Note] A temporary password is generated for root@localhost: nEU8fScMEm(M

配置mysql

[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@localhost mysql]# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig -v
//生成配置文件
[root@guohui ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF

配置启动脚本

[root@localhost mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# sed -ri ‘s#^(basedir=).*#\1/usr/local/mysql#g‘ /etc/init.d/mysqld
[root@localhost mysql]# sed -ri ‘s#^(datadir=).*#\1/opt/data#g‘ /etc/init.d/mysqld

启动mysql

[root@localhost mysql]# service mysqld start
Starting MySQL.Logging to ‘/opt/data/localhost.localdomain.err‘.
SUCCESS!
[root@localhost mysql]# ps -ef|grep mysql
root      24348      1  0 16:25 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql     24526  24348  2 16:25 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root      24556   2316  0 16:25 pts/0    00:00:00 grep --color=auto mysql
[root@localhost mysql]# ss -antl

修改临时密码

[root@localhost mysql]# mysql -uroot -p
Enter password:
mysql> set password = password(‘guohui123‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit

安装PHP
//安装依赖包

[root@localhost ~]# yum -y install bzip2-devel curl-devel freetype-devel gcc libjpeg-devel libpng-devel libxslt-devel libxml2-devel openssl-devel pcre-devel pcre-devel zlib-devel
//下载

[root@localhost ~]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
[root@localhost ~]# tar xf php-7.2.8.tar.xz
[root@localhost ~]# cd php-7.2.8
//配置安装变量,“/usr/local/php”是安装路径,可以改成自己喜欢的安装路径。

[root@localhost php-7.2.8]#./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
//编译源码,在解压目录执行编译命令:make

[root@localhost php-7.2.8]# make
//安装php
[root@localhost php-7.2.8]# make install
//配置PHP
将PHP源码包(/root/php-7.2.8)中的php.ini-development文件复制到/usr/local/php/下,更名为php.ini
源码包在root下下载,所以在root下

[root@localhost php-7.2.8]# cp /root/php-7.2.8/php.ini-development /usr/local/php/php.ini
[root@localhost php-7.2.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.2.8]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
配置php.ini “cgi.fix_pathinfo=0”
[root@localhost php-7.2.8]# vim /usr/local/php/php.ini
cgi.fix_pathinfo=0
启动php-fpm服务:
启动完毕之后,php-fpm服务默认使用9000端口
[root@localhost php-7.2.8]# /usr/local/php/sbin/php-fpm
[root@localhost php-7.2.8]# ss -anlt
LISTEN      0      128                  127.0.0.1:9000                                     *:*       
最后配置nginx
编辑nginx配置文件/usr/local/nginx/conf/nginx.conf ,主要修改nginx的server,{}配置块中的内容,修改location块,追加index.php让nginx服务器默认支持index.php为首页:
(在尾部追加了index.php)
2.更换为下方内容
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;
}

编辑更改

[root@localhost php-7.2.8]# vim /usr/local/nginx/conf/nginx.conf

1.
index  index.html index.htm;     更改成 index  index.html index.htm index.php;    

2.
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;
}
//这里面很多都是默认的,root是配置PHP程序放置的根目录,主要修改的就是fastcgi_param中的/
scripts为$document_root
修改完成这些保存并退出,然后重启nginx:/usr/local/nginx/sbin/nginx -s reload
接下来编辑一个测试的php程序,在nginx下的html目录下创建test.php文件,打印一下php配置:

[root@localhost ~]# cd /usr/local/nginx/html
[root@localhost html]# touch test.php
<?php
    phpinfo();
?>

然后打开浏览器输入对应的地址进行访问
http://192.168.56.11/test.php
技术分享图片

LINUX——lnmp架构的搭建,与lamp架构类似

标签:sed   php程序   sha   support   mat   params   启动脚本   c++   adb   

原文地址:http://blog.51cto.com/13859004/2170379

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!