欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

第二章 源码编译搭建 LAMP 架构

程序员文章站 2022-06-17 20:48:58
源码编译搭建 LAMP 架构实验环境silver3.cn192.168.43.31、配置好网络 yum 源 epel 源[root@silver3 yum.repos.d]# lsCentOS-Base.repo epel-7.repo[root@silver3 ~]# yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel#安装 make、 gcc、 openssl 等编译工具和开发包2、编译安装依赖包 apr...

源码编译搭建 LAMP 架构

实验环境

silver3.cn 192.168.43.3

1、配置好网络 yum 源 epel 源

[root@silver3 yum.repos.d]# ls

CentOS-Base.repo epel-7.repo

[root@silver3 ~]# yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel #安装 make、 gcc、 openssl 等编译工具和开发包

2、编译安装依赖包 apr

[root@silver3 ~]# tar xf apr-1.6.2.tar.gz -C /usr/local/
[root@silver3 ~]# cd /usr/local/apr-1.6.2/
[root@silver3 apr-1.6.2]# ./configure --prefix=/usr/local/apr

[root@silver3 apr-1.6.2]# make && make install

[root@silver3 apr-1.6.2]# echo $?
0

3、编译安装依赖包 apr-util

[root@silver3 ~]# tar xf apr-util-1.6.0.tar.gz -C /usr/local/
[root@silver3 ~]# cd /usr/local/apr-util-1.6.0/
[root@silver3 apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

[root@silver3 apr-util-1.6.0]# make && make install

4、编译安装依赖包 pcre

[root@silver3 ~]# tar xf pcre-8.41.tar.gz -C /usr/local/
[root@silver3 ~]# cd /usr/local/pcre-8.41/
[root@silver3 pcre-8.41]# ./configure --prefix=/usr/local/pcre

[root@silver3 pcre-8.41]# make && make install

5、编译安装 Apache

[root@silver3 ~]# tar xf httpd-2.4.37.tar.gz -C /usr/local/
[root@silver3 ~]# cd /usr/local/httpd-2.4.37/
[root@silver3 httpd-2.4.37]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=event

[root@silver3 httpd-2.4.37]# make && make install

[root@silver3 ~]# ls /usr/local/apache/conf/httpd.conf #配置文件
/usr/local/apache/conf/httpd.conf
[root@silver3 ~]# ls /usr/local/apache/htdocs/index.html #网站根目录
/usr/local/apache/htdocs/index.html

6、生成启动脚本

[root@silver3 ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/
[root@silver3 ~]# chmod +x /etc/init.d/apachectl

7、写个 apache 系统服务脚本, 以 754 的权限保存此文件

[root@silver3 ~]# vim /usr/lib/systemd/system/apache.service

[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

8、启动服务

[root@silver3 ~]# systemctl start apache
[root@silver3 ~]# systemctl enable apache

[root@silver3 ~]# netstat -anput
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::80 ::???? LISTEN 9626/httpd

9、修改 Apache 的运行用户

[root@silver3 ~]# id apache
id: apache: no such user
[root@silver3 ~]# useradd -M -s /sbin/nologin apache

[root@silver3 ~]# vim /usr/local/apache/conf/httpd.conf

改: 166 User daemon

为: 166 User apache

改:167 Group daemon

为:167 Group apache

10、更改目录权限

[root@silver3 ~]# chown -R apache.apache /usr/local/apache/

11、源码编译 mysql

MySQL 从 5.7 版本之后, boost 是必须的,建议把系统自带的 boost 库卸载,源码编译安装高版本

[root@silver3 ~]# yum -y remove boost-*

[root@silver3 ~]# yum -y remove mysql mariadb-*

[root@silver3 ~]# rm -rf /var/lib/mysql/* #删除旧的数据库

[root@silver3 ~]# yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel

[root@silver3 ~]# id mysql
id: mysql: no such user
[root@silver3 ~]# useradd -M -s /sbin/nologin mysql

[root@silver3 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 18G 1.6G 16G 9% /

[root@silver3 ~]# tar xvf mysql-boost-5.7.28.tar.gz -C /usr/local/src/

[root@silver3 mysql-5.7.28]# mkdir -p /var/lib/mysql/data
[root@silver3 mysql-5.7.28]# chown -R mysql.mysql /var/lib/mysql

[root@silver3 mysql-5.7.28]# cmake -DCMAKE_INSTALL_PREFIX=/var/lib/mysql \

-DMYSQL_DATADIR=/var/lib/mysql/data
-DSYSCONFDIR=/etc
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/local/src/mysql-5.7.28/boost/boost_1_59_0/

[root@silver3 mysql-5.7.28]# make -j 4 && make install

12、编辑配置文件

[root@silver3 ~]# vim /etc/my.cnf

[mysqld]
port=3306
user=mysql
basedir=/var/lib/mysql
datadir=/var/lib/mysql/data
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log

[mysql]
socket=/var/lib/mysql/mysql.sock

添加 path 路径, 让系统能读到 mysql 的命令

[root@silver3 ~]# vim /etc/profile

PATH=/var/lib/mysql/bin:$PATH

使环境变量修改生效

[root@silver3 ~]# source /etc/profile.d/mysql.sh

生成服务启动脚本

[root@silver3 ~]# cp /var/lib/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@silver3 ~]# chmod +x /etc/init.d/mysqld
[root@silver3 ~]# chown -R mysql.mysql /var/lib/mysql/

[root@silver3 ~]# touch /var/log/mysqld.log
[root@silver3 ~]# chown -R mysql.mysql /var/log/mysqld.log

初始化数据库:

[root@silver3 ~]# mysqld --defaults-file=/etc/my.cnf --initialize-insecure

启动服务:

[root@silver3 ~]# /etc/init.d/mysqld start
Starting MySQL… SUCCESS!

13、登陆 mysql 数据库

因初始化无密码,直接输入 mysql 可登陆:

[root@silver3 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 Source distribution

Copyright © 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.

mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
4 rows in set (0.00 sec)

mysql> exit

本文地址:https://blog.csdn.net/weixin_45471916/article/details/108852644

相关标签: Linux 运维 lamp