linux的LAMP架构说明及mysql安装
发布时间:2023-08-08 14:33:24 所属栏目:MySql教程 来源:
导读:LAMP架构介绍
LAMP是Linux+Apache(httpd)+MySQL+PHP的简写,即把Apache、MySQL以及PHP安装在linux系统上,组成一个运行环境来运行PHP脚本语言,通常是网站。比如Google、淘宝、百度、51cto博客、猿课论坛等就是用
LAMP是Linux+Apache(httpd)+MySQL+PHP的简写,即把Apache、MySQL以及PHP安装在linux系统上,组成一个运行环境来运行PHP脚本语言,通常是网站。比如Google、淘宝、百度、51cto博客、猿课论坛等就是用
LAMP架构介绍 LAMP是Linux+Apache(httpd)+MySQL+PHP的简写,即把Apache、MySQL以及PHP安装在linux系统上,组成一个运行环境来运行PHP脚本语言,通常是网站。比如Google、淘宝、百度、51cto博客、猿课论坛等就是用PHP语言写出来的。 httpd、PHP、MySQL三个角色可以在一台机器、也可以分开,但httpd和PHP要安装在一台机器上,这也是PHP作为Apache的一个模块存在的,它们两必须在一起。 httpd、PHP、MySQL三者如何工作: PHP是以模块的形式和Apache结合在一起的。 Apache不能直接跟Mysql打交道,只能通过PHP模块去Mysql拿数据,再交给Apache再交给用户。PHP与Mysql之间是动态请求。 MySQL、MariaDB介绍 MySQL是一个关系型数据库,由mysql ab公司开发,mysql在2008年被sun公司收购(10亿刀),2009年sun公司被oracle公司收购(74亿刀) MySQL官网https://www.mysql.com 最新版本5.7GA/8.0DMR; MySQL5.6变化比较大,5.7性能上有很大提升; Mariadb为MySQL的一个分支,官网https://mariadb.com/最新版本10.2; MariaDB主要由SkySQL公司(现更名为MariaDB公司)维护,SkySQL公司由MySQL原作者带领大部分原班人马创立; Mariadb5.5版本对应MySQL的5.5,10.0对应MySQL5.6; Community 社区版本,Enterprise 企业版,GA(Generally Available)指通用版本,在生产环境中用的,DMR(Development Milestone Release)开发里程碑发布版,RC(Release Candidate)发行候选版本,Beta开放测试版本,Alpha内部测试版本; MySQL安装 MySQL安装 MySQL的几个常用安装包:rpm包、源码包、二进制免编译包 查看linux系统是多少位: [root@gary ~]# uname -a Linux gary 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux 2.下载mysql源码包,把安装包放到指定目录下: [root@gary ~]# cd /usr/local/src [root@gary src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz --2017-12-14 19:17:14-- http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 正在解析主机 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140 正在连接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:314581668 (300M) [application/octet-stream] 正在保存至: “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz” 100%[===============================================================================>] 314,581,668 1.40MB/s 用时 3m 34s 2017-12-14 19:20:49 (1.40 MB/s) - 已保存 “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz” [314581668/314581668]) 3.将压缩包解压: [root@gary src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 4.把目录移动到/usr/local/下并改名为mysql: [root@gary src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql 5.进入目录查看: [root@gary src]# cd /usr/local/mysql [root@gary mysql]# ls bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files 6.创建mysql用户,创建目录/data/,用来存放mysql数据: [root@gary mysql]# useradd mysql [root@gary mysql]# mkdir /data/ 7.初始化指定用户mysql和路径: [root@gary-tao mysql]# ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper [root@gary mysql]# yum list |grep perl |grep -i dumper perl-Data-Dumper.x86_64 2.145-3.el7 base perl-XML-Dumper.noarch 0.81-17.el7 base [root@gary mysql]# yum install -y perl-Data-Dumper [root@gary-tao mysql]# echo $? //检验上一次命令是否成功,需要马上测验 0 [root@gary-tao mysql]# ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql //报错解决后再执行 解决办法: (执行后可能会出现这种情况,是因为缺少了一个模块,需要我们安装:yum install -y perl-Data-Dumper) 执行完命令后可马上执行命令echo $?查看是否为0,为0说明执行成功。 可能缺少的包: yum install -y libaio yum install -y numactl yum -y install libaio-devel yum -y install openssl-devel yum -y install perl perl-devel 安装centos 6.5 可以看下下面这篇文章: http://www.cnblogs.com/bookwed/p/5896619.html 拷贝配置文件,有两种方法: 方法一: 拷贝配置文件到etc目录下 cp support-files/my-default.cnf /etc/my.cnf 方法二: 更改自带的vim /etc/my.cnf文件,更改成如下配置: linux的LAMP架构介绍及mysql安装 9.复制启动脚本到/etc/init.d目录下并改名mysqld: [root@gary-tao mysql]# cp support-files/mysql.server /etc/init.d/mysqld 10.编辑启动脚本: [root@gary-tao mysql]# vi /etc/init.d/mysqld 定义basedir和datadir basedir=/usr/local/mysql datadir=/data/mysql linux的LAMP架构介绍及mysql安装 11.启动mysql: 看下默认权限是不是755,把服务加入开机启动。 root@gary-tao mysql]# ls -l /etc/init.d/mysqld //默认权限 -rwxr-xr-x 1 root root 10902 12月 14 20:57 /etc/init.d/mysqld [root@gary-tao mysql]# chkconfig --add mysqld //添加开机启动 [root@gary-tao mysql]# chkconfig --list //查看已添加开机 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。 欲查看对特定 target 启用的服务请执行 'systemctl list-dependencies [target]'。 mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关 network 0:关 1:关 2:开 3:开 4:开 5:开 6:关 手动启动mysql服务命令 [root@gary mysql]# /etc/init.d/mysqld start 或者 service mysqld start [root@gary mysql]# service mysqld start //服务启动成功 Starting MySQL.Logging to '/data/mysql/gary.err'. ..... SUCCESS! [root@gary mysql]# ps aux |grep mysql //查看进程 root 8081 0.0 0.1 11760 1588 pts/0 S 21:23 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/gary.pid mysql 8216 0.9 44.9 973048 449520 pts/0 Sl 21:23 0:05 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/gary.err --pid-file=/data/mysql/gary.pid --socket=/tmpmysql.sock root 8258 0.0 0.0 112664 972 pts/0 S+ 21:32 0:00 grep --color=auto mysql [root@gary mysql]# netstat -lntp //查看监听端口3306 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:22 0.0.0.0:* LISTEN 827/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1102/master tcp6 0 0 :::3306 :::* LISTEN 8216/mysqld tcp6 0 0 :::22 :::* LISTEN 827/sshd tcp6 0 0 ::1:25 :::* LISTEN 1102/master 假设: 如果没有启动脚本可以放在/etc/init.d下,那么可以用命令的方式来打开mysql(PS:命令模式打开的mysql要关闭需要用kill命令:killall mysqld,也可以用 kill PID号,但是建议用killall,就如mysql如果用killall,它会先停止当前的读写操作,再把没有完成写入磁盘的数据慢慢写进去,直到写完之后才会把进程杀死。如果遇到mysqld进程杀不死,等了一分钟还杀不死,说明数据量很大,慢慢等,不要强制使用kill -9 。) 命令: /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql & –defaults-file:指定配置文件所在的路径。 示例如下: [root@gary mysql]# service mysqld stop //停止mysql服务 Shutting down MySQL.. SUCCESS! [root@gary mysql]# ps aux |grep mysql //查看进程停止 root 8290 0.0 0.0 112664 968 pts/0 S+ 21:38 0:00 grep --color=auto mysql [root@gary mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql & //执行命令启动服务,这里按ctrl+z把命令放到后台执行 [1] 8472 [root@gary mysql]# 171214 21:42:10 mysqld_safe Logging to '/data/mysql/gary.err'. 171214 21:42:10 mysqld_safe Starting mysqld daemon with databases from /data/mysql [root@gary mysql]# ps aux |grep mysql //进程启动 root 8472 0.0 0.1 113256 1584 pts/0 S 21:42 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql mysql 8595 0.3 45.6 973048 456372 pts/0 Sl 21:42 0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/gary.err --pid-file=/data/mysql/gary.pid --socket=/tmp/mysql.sock root 8620 0.0 0.0 112664 968 pts/0 S+ 21:46 0:00 grep --color=auto mysql [root@gary mysql]# yum install psmisc //安装killall命令 [root@gary mysql]# killall mysqld //终止以命令方式启动的mysql服务 [root@gary mysql]# ps aux |grep mysql //查看进程已结束 root 8642 0.0 0.0 112664 972 pts/0 R+ 21:54 0:00 grep --color=auto mysql (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐