传统IDC部署网站(五)

21. LNMP环境介绍

linux +Nginx +mysql/mariadb +PHPphp

Nginx

是一个web服务器,提供HTTP服务的css

Mysql/Mariadb

是一个关系型数据库,是用来存数据的( 用户名、密码、文章、内容)mysql

PHP

是一个编程语言,经常使用来作网站linux

三者的关系

用户先会先访问Nginx (静态请求 ,会处理图片,JS,CSS,接收php的请求,可是不处理)把php的请求转发到后面的php-fpmweb

php-fpm 会处理php相关的请求(叫作动态的请求)sql

动态,静态

静态: 指的是Nginx能够直接处理图片、js、css 视频、音频、flash等等数据库

动态: 指的是这些请求须要和数据库打交道,好比 ,用户登录过程,好比查看一篇文章,或者写一篇文章编程

22. Mariadb安装(上)

MariaDB是MySQL的一个分支。 MySQL -- SUN --- Oraclevim

官网 https://mariadb.org服务器

下载mariadb

[root@localhost src]# wget https://downloads.mariadb.org/interstitial/mariadb-10.3.11/bintar-linux-x86_64/mariadb-10.3.11-linux-x86_64.tar.gz

解压

[root@localhost src]# tar zxvf mariadb-10.3.11-linux-x86_64.tar.gz
tar zxvf XXX.tar.gz    z:针对gz压缩
tar jxvf XXX.tar.bz2   j:针对bz2压缩
tar Jxvf XXX.tar.xz    J:针对xz压缩

压缩

tar zcvf XXX.tar.gz  XXX/   
tar jcvf XXX.tar.bz2 XXX/
tar Jcvf XXX.tar.xz XXX/

23. Mariadb安装(中)

移动并更名 /usr/local/mysql

[root@localhost src]# mv mariadb-10.3.11-linux-x86_64 /usr/local/mysql

建立目录 及帐号

[root@localhost mysql]# mkdir -p /data/mysql
[root@localhost mysql]# useradd -M -s /sbin/nologin mysql
[root@localhost mysql]# grep mysql /etc/passwd
mysql:x:1000:1000::/home/mysql:/sbin/nologin
[root@localhost mysql]# chown -R mysql:mysql /data/mysql

初始化设置

[root@localhost mysql]# ./scripts/mysql_install_db  --datadir=/data/mysql --usr=mysql

验证是否成功 输出是0是正确的 不正确的状况显示的是1

[root@localhost mysql]# echo $?
0

拷贝启动脚本

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

编辑启动脚本

[root@localhost mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql

启动服务

[root@localhost mysql]# /etc/init.d/mysqld start

24. 服务管理

列出系统全部的服务

chkconfig --list    rhel6
systemctl list-unit-files  rhel7

chkconfig 增长服务

/etc/init.d/下有mysqld 而且权限是755

[root@localhost init.d]# pwd
/etc/init.d
[root@localhost init.d]# ll |grep mys
-rwxr-xr-x. 1 root root 12193 Jan 24 00:39 mysqld
[root@localhost mysql]# chkconfig --add mysqld

开机启动服务

chkconfig mysqld off
chkconfig mysqld on
# 25. Mariadb安装(下)

## 修改配置文件my.cnf

[root@localhost init.d]# vim /etc/my.cnf

datadir=/data/mysql socket=/tmp/mysql.sock log-error=/data/mysql/mariadb.log pid-file=/data/mysql/mariadb.pid

## 启动服务

[root@localhost mysql]# service mysqld start Starting mysqld (via systemctl): [ OK ]

## 查看是否启动成功

[root@localhost mysql]# netstat -lnp |grep 3306 tcp6 0 0 :::3306 :::* LISTEN 5822/mysqld [root@localhost mysql]# netstat -lnp |grep 3306 tcp6 0 0 :::3306 :::* LISTEN 5822/mysqld

 

[root@localhost mysql]# ls -l /tmp/mysql.sock srwxrwxrwx. 1 mysql mysql 0 Jan 24 01:32 /tmp/mysql.sock

## 链接

[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

##

[root@localhost mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

## 系统环境变量 (不建议用)

[root@localhost mysql]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

[root@localhost mysql]# PATH=$PATH:/usr/local/mysql/bin [root@localhost mysql]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin [root@localhost mysql]#echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile source /etc/profile

## 设置密码

[root@localhost mysql]# mysqladmin -uroot password "123"

## 登录

[root@localhost mysql]# mysql -uroot -p123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>

 

[root@localhost mysql]# mysql -uroot -p123 -S/tmp/mysql.sock Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 15 Server version: 10.3.11-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

 

[root@localhost mysql]# mysql -uroot -p123 -h192.168.222.128 -P3306

相关文章
相关标签/搜索