Cent OS 7.4 源码搭建LAMP

Posted kjjmj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cent OS 7.4 源码搭建LAMP相关的知识,希望对你有一定的参考价值。

一.安装mysql,装备的安装包:mysql-5.7.12.tar.gz boost_1_59_0.tar.gz

1.下载软件包

[[email protected] ~]#wget http://dev.mysql.com/Downloads/MySQL-5.7/mysql-5.7.12.tar.gz

[[email protected] ~]#wget  https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download

  

2.卸载原先的原先的MySQL和boost,并检查

[[email protected] ~]#yum -y remove mysql-* boost-*

[[email protected] ~]#rpm -qa mysql

[[email protected] ~]#rpm -qa boost

  

3.安装MySQL需要的依赖包

[[email protected] ~]#yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl cmake

  

4.解压boost到指定路径下,安装MySQL的时候要指定这个路径的

[[email protected] ~]#tar -xf boost_1_59_0.tar.gz -C /usr/local/boost/

  

5.创建MySQL的运行用户,并查看下

[[email protected] ~]#groupadd mysql

[[email protected] ~]#useradd -r -g mysql mysql

[[email protected] ~]#id mysql

  

6.解压MySQL,并进入到解压目录

[[email protected] ~]#tar -xf mysql-5.7.12.tar.gz -C /usr/src

[[email protected] ~]#cd /usr/src/mysql-5.7.12

  

7.配置、编译、安装

   

[[email protected] mysql-5.7.12]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost -DSYSCONFDIR=/etc
[[email protected] mysql-5.7.12]#make && make install

  

可以make -j 来指定编译时用到的核心数来提高编译速度,如:指定用4个核心来安装:make -j 4

8.优化调整MySQL

[[email protected] mysql-5.7.12]#chown -R mysql:mysql /usr/local/mysql        #赋权

[[email protected] mysql-5.7.12]#cp /usr/src/mysql-5.7.12/support-files/my-default.cnf /etc/my.cnf        #复制配置文件

[[email protected] mysql-5.7.12]#cp /usr/src/mysql-5.7.12/support-files/mysql.server /etc/init.d/        #复制启动脚本到系统服务目录下

[[email protected] mysql-5.7.12]#chmod +x /etc/init.d/mysql.server        #添加可执行权限

  

编写服务控制脚本:

[[email protected] mysql-5.7.12]#cat <<END >>/usr/lib/systemd/system/mysqld.service     

[Unit]

Description=mysqldapi

After=network.target

[Service]

Type=forking

PIDFile=/usr/local/mysql/logs/mysqld.pid

ExecStart=/etc/init.d/mysql.server start

ExecReload=/etc/init.d/mysql.server restart

ExecStop=/etc/init.d/mysql.server stop

PrivateTmp=Flase

[Install]

WantedBy=multi-user.target

END

[[email protected] mysql-5.7.12]#echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile && source /etc/profile        #将MySQL的命令添加到环境变量

[[email protected] mysql-5.7.12]#mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data        #初始化MySQL

  

修改MySQL配置文件:

[[email protected] mysql-5.7.12]#cat <<END >/etc/my.cnf

[mysqld]

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

character_set_server=utf8

init_connect=‘SET NAMES utf8‘

log-error=/usr/local/mysql/logs/mysqld.log

pid-file=/usr/local/mysql/logs/mysqld.pid

END

[[email protected] mysql-5.7.12]#mkdir /usr/local/mysql/logs && chown mysql:mysql /usr/local/mysql/logs/        #创建MySQLlog文件并重新赋权

[[email protected] mysql-5.7.12]#systemctl start mysqld        #启动服务

[[email protected] mysql-5.7.12]#systemctl enable mysqld        #设置开机自启

  

9.登陆MySQL,并修改密码

[[email protected] mysql-5.7.12]#mysql        #初始化之后默认没有密码,直接输入mysql就可以登陆了

[[email protected] mysql-5.7.12]#alter user ‘root‘@‘localhost‘ identified by ‘root‘;        #修改密码

  

 

以上是关于Cent OS 7.4 源码搭建LAMP的主要内容,如果未能解决你的问题,请参考以下文章

Linux精华篇—CentOS 7.4下源码编译构建LAMP架构

Cent OS 7 搭建Discuz论坛流程

lamp源码搭建详解及wordpress搭建

lamp源码搭建详解及wordpress搭建

源码编译搭建LAMP环境

Centos7.4源码搭建LAMP环境