1、JAVA、Web环境
[tomcat(jvm)]、resin、jboss、Weblogic
配合nginx proxy_pass代理功能
2、python Web环境
配合nginx uwsgi_pass代理功能
3、PHP Web环境
配合nginx fastcgi_pass代理功能
4、GO语言
单机安装LNMP:
一、先装MySQL数据库:
1.创建用户
[root@web02~]# useradd mysql -s /sbin/nologin -M #=====>创建用户
[root@web02~]# id mysql #=====>查看是否创建成功
uid=1017(mysql) gid=1017(mysql) groups=1017(mysql)
2、上传或下载软件
root@web02/server/tools]# ls -lsh #=====>查看上传的文件大小,是否完整
total 616M
615M -rw-r--r-- 1 root root 615M May 4 20:48 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
0 drwxr-xr-x 9 oldboy1 oldboy1 204 Apr 30 17:44 nginx-1.16.0
1012K -rw-r--r-- 1 root root 1009K Apr 23 21:58 nginx-1.16.0.tar.gz
[root@web02/server/tools]# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz #=====>解压文件
[root@web02/server/tools]# ll #=====>查看一下
total 630768
drwxr-xr-x 9 root root 129 May 6 14:42 mysql-5.7.26-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root 644869837 May 4 20:48 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x 9 oldboy1 oldboy1 204 Apr 30 17:44 nginx-1.16.0
-rw-r--r-- 1 root root 1032345 Apr 23 21:58 nginx-1.16.0.tar.gz
[root@web02/server/tools]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql-5.7.26 #=====>移动文件到/application/mysql-5.7.26中
[root@web02/server/tools]# ln -s /application/mysql-5.7.26/ /application/mysql #=====>
3.配置配置文件/etc/my.cnf
[root@web02/server/tools]# rpm -e --nodeps mariadb-libs
[root@web02/server/tools]# ls -l /etc/my.cnf
ls: cannot access /etc/my.cnf: No such file or directory
[root@web02/server/tools]#
[root@web02/server/tools]# vim /etc/my.cnf #=====>编辑配置文件
[mysqld]
basedir = /application/mysql/
datadir = /application/mysql/data
socket = /tmp/mysql.sock
server_id = 1
port = 3306
log_error = /application/mysql/data/oldboy_mysql.err
[mysql]
socket = /tmp/mysql.sock
prompt = oldboy [\\d]>
~
~
~
~
~
~
~
~
~
"/etc/my.cnf" [New] 12L, 235C written
4.初始化数据库
[root@web02/server/tools]# rpm -qa mariadb-libs #=====>查看一下,mariadb是否存在,应为不存在
[root@web02/server/tools]# yum install libaio-devel -y
[root@web02/server/tools]# mkdir -p /application/mysql/data #=====>创建目录
[root@web02/server/tools]# chown -R mysql.mysql /application/mysql #=====>设置用户、用户组
[root@web02/server/tools]# /application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data #=====>
5.配置启动服务
[root@web02/server/tools]# vim /etc/systemd/system/mysqld.service #=====>配置文件,以下为配置内容
[Unit]
Description=MySQL Server by oldboy
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=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
~
~
~
~
~
~
~
~
"/etc/systemd/system/mysqld.service" [New] 13L, 336C written
[root@web02/server/tools]# systemctl start mysqld #=====>开启服务
[root@web02/server/tools]# systemctl enable mysqld #=====>设置为自启
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /etc/systemd/system/mysqld.service.
[root@web02/server/tools]# systemctl status mysqld #=====>查看服务状态
● mysqld.service - MySQL Server by oldboy
Loaded: loaded (/etc/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-05-06 15:16:50 CST; 23s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 7349 (mysqld)
CGroup: /system.slice/mysqld.service
└─7349 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
May 06 15:16:50 web02 systemd[1]: Started MySQL Server by oldboy.
[root@web02/server/tools]# netstat -lntup|grep mysql #=====>查看服务进程
tcp6 0 0 :::3306 :::* LISTEN 7349/mysqld
[root@web02/server/tools]# ps -ef|grep mysql|grep -v grep #=====>
mysql 7349 1 0 15:16 ? 00:00:00 /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
6.配置环境变量登录
[root@web02/server/tools]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile #=====>配置环境变量
[root@web02/server/tools]# tail -1 /etc/profile #=====>查看是否配置
export PATH=/application/mysql/bin:$PATH
[root@web02/server/tools]# . /etc/profile #=====>使配置生效
[root@web02/server/tools]# echo $PATH #=====>查看环境变量
/application/mysql/bin:/application/nginx/sbin:/application/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@web02/server/tools]# mysql #=====>登录 出现如下画面说明MySQL安装、配置成功,输入“quit”或者按“Ctrl键+D键”退出。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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.
oldboy [(none)]>quit
Bye
7.修改密码
[root@web02/server/tools]# mysqladmin -u root password 'oldboy123'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@web02/server/tools]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
重新登录:(两种登录方式)
1.交互式登录:
[root@web02/server/tools]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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.
oldboy [(none)]>^DBye
2.非交互式登录:
[root@web02/server/tools]# mysql -uroot -poldboy123
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 7
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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.
oldboy [(none)]>^DBye
[root@web02/server/tools]#
二、安装PHP
1.安装PHP调用的库
[root@web02/~]# yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
[root@web02/~]# yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
[root@web02/~]# cd /server/tools
上传(下载)libiconv文件
[root@web02/server/tools]# tar xf libiconv-1.16.tar.gz #=====>解压文件
[root@web02/server/tools]# cd libiconv-1.16/ #=====>移动到 libiconv-1.16中
[root@web02/server/tools/libiconv-1.16]#
[root@web02/server/tools/libiconv-1.16]# ./configure --prefix=/application/libiconv #=====>
[root@web02/server/tools/libiconv-1.16]# make && make install #=====> 编译
[root@web02/server/tools/libiconv-1.16]# echo $? #=====> 若为0,则说明前面步骤成功
0
[root@web02/server/tools]# yum install libmcrypt-devel -y #=====>下载软件
[root@web02/server/tools]# yum install mhash -y
[root@web02/server/tools]# yum install mcrypt -y
2.安装PHP
[root@web02/server/tools]# rz -E
rz waiting to receive.
[root@web02/server/tools]# ll
total 654804
drwxrwxr-x 20 root root 4096 May 6 16:15 libiconv-1.16
-rw-r--r-- 1 root root 5166734 May 6 10:54 libiconv-1.16.tar.gz
lrwxrwxrwx 1 root root 26 May 6 14:51 mysql-5.7.26 -> /application/mysql-5.7.26/
-rw-r--r-- 1 root root 644869837 May 4 20:48 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x 9 oldboy1 oldboy1 204 Apr 30 17:44 nginx-1.16.0
-rw-r--r-- 1 root root 1032345 Apr 23 21:58 nginx-1.16.0.tar.gz
-rw-r--r-- 1 root root 19439026 May 6 11:00 php-7.3.5.tar.gz
[root@web02/server/tools]# tar xf php-7.3.5.tar.gz
[root@web02/server/tools]# cd php-7.3.5/
[root@web02/server/tools/php-7.3.5]# ./configure --prefix=/application/php-7.3.5 --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/application/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --enable-opcache=no
[root@web02/server/tools/php-7.3.5]# make && make install
[root@web02/server/tools/php-7.3.5]# echo $?
0
[root@web02/application/php/etc/php-fpm.d]# useradd nginx -u 1111 -s /sbin/nologin -M
[root@web02/application/php/etc/php-fpm.d]# id nginx
uid=1111(nginx) gid=1111(nginx) groups=1111(nginx)
3.配置php.ini(PHP解析器配置文件)
[root@web02/application]# ln -s /application/php-7.3.5/ /application/php
[root@web02/application]# ls /application/php/
bin etc include lib php sbin var
[root@web02/application]# ln -s /application/php-7.3.5/ /application/php
[root@web02/application]# ls /application/php/
bin etc include lib php sbin var
[root@web02/application]# cd /server/tools/php-7.3.5/
[root@web02/server/tools/php-7.3.5]# ls php.ini-*
php.ini-development php.ini-production
[root@web02/server/tools/php-7.3.5]# cp php.ini-development /application/php/lib/php.ini
[root@web02/server/tools/php-7.3.5]# ls -l /application/php/lib/php.ini
-rw-r--r-- 1 root root 71648 May 6 16:47 /application/php/lib/php.ini
4.配置PHP FPM
[root@web02/server/tools/php-7.3.5]# cd /application/php/etc/
[root@web02/application/php/etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@web02/application/php/etc]# cp php-fpm.conf.default php-fpm.conf
[root@web02/application/php/etc]# cd php-fpm.d
[root@web02/application/php/etc/php-fpm.d]# ls
www.conf.default
[root@web02/application/php/etc/php-fpm.d]# cp www.conf.default www.conf
[root@web02/application/php/etc/php-fpm.d]# ls
www.conf www.conf.default
5.启动PHP服务
[root@web02/application/php/etc/php-fpm.d]# /application/php/sbin/php-fpm
[root@web02/application/php/etc/php-fpm.d]# netstat -lntup|grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 11865/php-fpm: mast
6.开机自启动
7.配置nginx转发PHP请求
[root@web02/application/nginx/conf/extra]# vim 03_blog.conf
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
~
~
~
~
~
~
"03_blog.conf" 15L, 280C written
8.测试nginx连接PHP
[root@web02/application/nginx/conf]# echo "<?php phpinfo(); ?>" > ../html/blog/test_info.phpc
[root@web02/application/nginx/conf]# cat ../html/blog/test_info.phpc
<?php phpinfo(); ?>
[root@web02 /application/nginx/conf]# nginx -t
nginx: the configuration file /application/nginx-1.16.0//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.16.0//conf/nginx.conf test is successful
[root@web02 /application/nginx/conf]# nginx -s reload
测试:浏览器输入:blog.etiantian.org/test_info.php
出现下图,则说明配置成功!
9.
[root@web02/application/nginx/conf]# vim /application/nginx/html/blog/test_mysql.php
<?php
//$link_id=mysqli_connect('主机名','用户','密码');
$link_id=mysqli_connect('localhost','root','oldboy123') or mysql_error();
if($link_id){
echo "mysql successful by oldboy.\n";
}else{
echo mysql_error();
}
?>
~
~
~
~
~
~
~
~
~
~
~
~
<cation/nginx-1.16.0/html/blog/test_mysql.php" [New] 9L, 230C written
[root@web02/application/nginx/conf]# /application/php/bin/php /application/nginx/html/blog/test_mysql.php
mysql successful by oldboy.
测试:浏览器输入:blog.etiantian.org/test_mysql.php
出现下图,则说明配置成功!
网友评论