搭建lnmp环境
1、安装软件依赖包:
yum -y groupinstall "Development Tools" "Server Platform Deveopment"
yum -y install openssl-devel pcre-devel
2、在所有的主机上面都操作,下载nginx包:
cd /usr/local/src/
[root@node1 src]# yum install wget –y ##安装wget工具
3、下载nginx包:
[root@node1 src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
4、添加nginx运行的用户:
[root@node1 sbin]# useradd nginx
5解压nginx包,并且安装:
[root@node1 src]# tar zxvf nginx-1.12.0.tar.gz
[root@node1 src]# cd nginx-1.12.0/
6、安装nginx包:
[root@node1 nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre
###编译安装
[root@node1 nginx-1.12.0]# make && make install
6、然后我们可以启动nginx:
[root@node2 nginx]# cd /usr/local/nginx/sbin/
[root@node1 sbin]# ./nginx
##假如已经存在进程:
[root@node2 sbin]# ps -ef | grep nginx | awk '{print $2}' | xargs kill -9
kill: 向 9132 发送信号失败: 没有那个进程
7、我们可以查看我们的IP,然后访问web界面查看一下:
[root@node1 sbin]# ifconfig
eth0: flags=4163
inet 119.29.11.175 netmask 255.255.192.0 broadcast 10.104.191.255
ether 52:54:00:9b:4b:a0 txqueuelen 1000 (Ethernet)
RX packets 113077 bytes 123521930 (117.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 45620 bytes 4211893 (4.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
8、查看一下是否监听到端口:
[root@node1 sbin]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8035/nginx: master
访问web:
##以上步骤在每台上面都执行:
Setup2:
1、下载依赖包:
cd /usr/local/src
[root@node2 src]# yum -y install libmcrypt-devel bzip2-devel gcc openssl-devel php-mcrypt libmcrypt libxml2-devel libjpeg-devel libpng-devel freetype-devel
2、下载Php包:
[root@node2 src]# wget http://cn2.php.net/distributions/php-5.5.38.tar.gz
3、安装php包:
[root@node2 src]# tar zxvf php-5.5.38.tar.gz
[root@node2 src]# cd php-5.5.38/
[root@node2 php-5.5.38]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-bz2 --enable-fpm --with-gd
要显示成这样才是正常的:
4、开始编译安装:
[root@node2 php-5.5.38]# make && make install
##注意要编译没有报错:
5、开始一些配置步骤:
[root@node2 php-5.5.38]# cp /usr/local/src/php-5.5.38/php.ini-production /usr/local/php/etc/php.ini
[root@node2 php-5.5.38]# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
6、创建Php用户:
[root@node2 php-5.5.38]# useradd -M -s /sbin/nologin php
7、修改相关配置:
[root@node2 php-5.5.38]# sed -i -e 's\;pid = run/php-fpm.pid\pid = run/php-fpm.pid\g' -e 's\nobody\php\g' -e 's\listen = 127.0.0.1:9000\listen = 0.0.0.0:9000\g' /usr/local/php/etc/php-fpm.conf
[root@node2 php-5.5.38]# sed -i 's\;daemonize = yes\daemonize = no\g' /usr/local/php/etc/php-fpm.conf
8、启动php:
[root@node2 php-5.5.38]# /usr/local/php/sbin/php-fpm &
9、查看一下是否已经启动了php:
[root@node2 php-5.5.38]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0: LISTEN 1/systemd
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 31587/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0: LISTEN 734/sshd
tcp 0 0 0.0.0.0:9000 0.0.0.0: LISTEN 1114/php-fpm: maste
tcp6 0 0 :::111 ::: LISTEN 14694/rpcbind
tcp6 0 0 :::22 ::: LISTEN 734/sshd
##注意是9000端口:
Setup3:
[root@node2 php-5.5.38]# yum install mariadb-server mariadb –y
2、启动mysql:
systemctl start mariadb
2、设置root账户,用户名密码:
[root@node2 php-5.5.38]# mysql_secure_installation
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
will take effect immediately.
Reload privilege tables now? [Y/n]
... Success!
Thanks for using MariaDB!
4、创意一个wordpress数据库:
[root@node2 php-5.5.38]# mysql -uroot -p123456 -e "create database wordpress"
[root@node2 php-5.5.38]# mysql -uroot -p123456 -e "show databases"
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| wordpress |
+--------------------+
##验证拥有数据库了即可。
给数据库授权:
[root@node2 conf]# mysql -uroot -p123456 -e "grant all privileges on . to 'root'@'%' identified by '123456'; FLUSH PRIVILEGES;"
Setup4:
在web01,web02上面设置nginx相关web相关服务,然后上传wordpress代码:
[root@node2 php-5.5.38]# mkdir /web
[root@node2 php-5.5.38]# cd /web/
[root@node2 web]# tar zxvf /usr/local/src/wordpress-4.7.2-zh_CN.tar.gz -C /web/
[root@node2 web]# cp –r wordpress/* /web
[root@node2 web]# cp wordpress/wp-admin wordpress/wp-content wordpress/wp-includes -r /web
2、上传配置文件到nginx目录,我已经配置好,从本机上传即可:
[root@node2 web]# cd /usr/local/nginx/conf/
[root@node2 web]# rm nginx.conf
[root@node2 web]# rz ##上传文件到目录下
###我们看一下我们应该如何配置:#########
location /{
root /web;
index index.php index.html index.htm;
}
location ~ .php$ {
root /web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3、然后启动nginx:
[root@node2 conf]# /usr/local/nginx/sbin/nginx
要是已经存在服务会提示:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
就执行一下操作:
[root@node2 conf]# /usr/local/nginx/sbin/nginx -s reload
5、然后输入浏览器地址:IP/index.php即可: