百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 热门文章 > 正文

编译LNMP环境 lnmp配置

bigegpt 2024-10-09 08:05 5 浏览

一、编译Mysql

版本5.7.11

  • 1、目录
源码目录

mkdir -p /opt/source

mysql安装目录 

mkdir -p /usr/local/mysql

MySQL数据目录 

mkdir -p /webserver/data/mysql

创建不能登陆的mysql用户

useradd -s /sbin/nologin mysql
  • 2 下载mysql源码

下载带boost库版本的源码

cd /opt/source

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.11.tar.gz
  • 3、安装编译环境
yum groupinstall 'Development Tools'

yum install cmake
  • 4 安装依赖库文件
yum install ncurses-devel
  • 5 编译mysql

5.1 生成makefile

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/webserver/data/mysql -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 -DWITH_BOOST=/opt/source/mysql-5.7.11/boost

5.2 编译mysql

make -j4

make install

5.3 初始化mysql数据

首先创建mysql用户

cd /usr/local/mysql/bin

./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/webserver/data/mysql

执行完后会提示一个root的密码

5.4 配置mysql环境

1、生成my.cnf文件

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

修改配置如下:

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[client]

port=3306

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

[mysqld]

datadir=/webserver/data/mysql

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

init-connect = 'SET NAMES utf8mb4'

character-set-server = utf8mb4

skip-name-resolve

server-id=1

back_log = 300

max_connections = 2000

max_connect_errors = 6000

open_files_limit = 1024

table_open_cache = 128

max_allowed_packet = 500M

binlog_cache_size = 1M

max_heap_table_size = 8M

tmp_table_size = 16M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

sort_buffer_size = 8M

join_buffer_size = 8M

key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1

query_cache_size = 8M

query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin

binlog_format = mixed

expire_logs_days = 7

performance_schema = 0

#lower_case_table_names = 1

skip-external-locking

default_storage_engine = InnoDB

innodb_file_per_table = 1

innodb_open_files = 500

innodb_buffer_pool_size = 64M

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_thread_concurrency = 0

innodb_purge_threads = 1

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 2M

innodb_log_file_size = 32M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M

myisam_sort_buffer_size = 8M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

interactive_timeout = 28800

wait_timeout = 28800

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# socket = .....

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

slow_query_log = 1

long_query_time = 1

[mysqldump]

quick

max_allowed_packet = 500M

[myisamchk]

key_buffer_size = 20M

sort_buffer_size = 20M

read_buffer = 2M

write_buffer = 2M

[mysql]

no-auto-rehash

[mysqlhotcopy]

interactive-timeout

2、创建启动脚本

cp -R /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld

5.5 启动mysql

mkdir -p /var/run/mysqld

chown -R mysql:mysql /var/run/mysqld/

/etc/init.d/mysqld start

如果出错,可以看日志文件

cat /var/log/mysqld.log

5.6 修改mysql密码

[root@tomato ~]# mysqladmin -uroot -hlocalhost -p password password.lehoon.com

Enter password:     输入旧密码默认为空

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的密码为password.lehoon.com

5.7 创建用户

--创建数据库

create database yigoutong default character set utf8 collate utf8_general_ci;

--创建用户

create user 'yigoutong'@'localhost' identified by 'yigoutong@lehoon.com';

--授权

grant select, insert, update,delete,create on yigoutong.* to yigoutong;

--所有权限

grant all on yigoutong.* to yigoutong;

--刷新立即生效

flush privileges;

5.8 导入数据库

mysql -ushop -p shop < shop_20200318.sql

输入密码,执行完数据就导入数据库

二、编译php7.1.33

  • 2.1 下载源码
cd /opt/source

wget https://www.php.net/distributions/php-7.1.33.tar.gz

解压源码

tar zxvf php-7.1.33.tar.gz
  • 2.2 修改ld路径

vi /etc/ld.so.conf.d/local.conf

添加

/usr/local/lib

/usr/local/lib64

保存,后执行命令ldconfig -v

  • 2.3 安装依赖库文件
yum install  libxml2 libxml2-devel

yum -y install openssl-devel

yum install curl-devel

yum install libpng -y

yum install libpng-devel -y

yum -y install libjpeg-devel

yum -y install freetype-devel
  • 2.3.1 安装mcrypt库
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz

tar -zxvf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7

./configure

make 

make install
  • 2.4 编译php
cd /opt/source/php-7.1.33

./configure --prefix=/usr/local/php7.1.33 --exec-prefix=/usr/local/php7.1.33 --bindir=/usr/local/php7.1.33/bin --sbindir=/usr/local/php7.1.33/sbin --includedir=/usr/local/php7.1.33/include --libdir=/usr/local/php7.1.33/lib/php --mandir=/usr/local/php7.1.33/php/man --with-config-file-path=/usr/local/php7.1.33/etc --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl  --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --disable-phar --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --without-gdbm --disable-fileinfo

完成后,执行

make -j4

make install
  • 2.5 安装服务
cp -R /opt/source/php-7.1.33/sapi/fpm/php-fpm.service /usr/lib/systemd/system/

systemctl enable php-fpm.service
  • 2.6 编辑php-fpm配置文件

主要包括:

/usr/local/php-7.1.33/etc/php.ini

/usr/local/php-7.1.33/etc/php-fpm.conf

/usr/local/php-7.1.33/etc/php-fpm.d/www.conf

同时创建sock文件目录

mkdir -p /var/run/php-fpm

chown -R nginx:nginx /var/run/php-fpm
  • 2.7 编译扩展

2.7.1 yaf扩展

打开网址 https://pecl.php.net/package/yaf 选择合适的版本下载

cd /opt/source

wget https://pecl.php.net/get/yaf-3.2.5.tgz

tar zxvf yaf-3.2.5.tgz

cd yaf-3.2.5

phpize

configure --with-php-config=/usr/local/php7.1.33/bin/php-config 

make

make install

2.7.2 redis扩展

打开网址 https://pecl.php.net/package/redis,下载最新版本

cd /opt/source

wget https://pecl.php.net/get/redis-5.2.2.tgz

tar zxvf redis-5.2.2.tgz

cd redis-5.2.2

phpize

configure --with-php-config=/usr/local/php7.1.33/bin/php-config

make

make install

2.7.3 fileinfo扩展

cd /opt/source/php-7.1.33/ext/fileinfo

phpize

configure --with-php-config=/usr/local/php7.1.33/bin/php-config

make

make install

2.7.4 pdo_mysql扩展

cd /opt/source/php-7.1.33/ext/pdo_mysql

phpize

configure --with-php-config=/usr/local/php7.1.33/bin/php-config

make

make install

2.7.5 修改php.ini

vi /usr/local/php-7.1.33/etc/php.ini

extension=yaf.so

extension=redis.so

extension=fileinfo.so

extension=pdo_mysql.so

zend_extension=opcache.so

2.8 启动php-fpm服务

systemctl start php-fpm.service

三、编译nginx

下载nginx最新源码

wget http://nginx.org/download/nginx-1.19.0.tar.gz

tar zxvf nginx-1.19.0.tar.gz

cd nginx-1.19.0

./configure --prefix=/usr/local/nginx --with-file-aio --user=nginx --group=nginx  --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module

make 

make install

四、编译redis

  • 4.1 下载源码

打开网址 https://github.com/antirez/redis/releases,选择版本下载,需要注意的是6.0版本以上需要gcc 5以上才能编译,所以根据本地gcc版本选择合适的redis版本。

cd /opt/source

wget https://github.com/antirez/redis/archive/5.0.8.tar.gz -O redis-5.0.8.tar.gz

tar zxvf redis-5.0.8.tar.gz 

cd redis-5.0.8

make

mkdir -p /usr/local/redis

cd src

cp -R redis-cli /usr/local/redis/

cp -R redis-server /usr/local/redis/

cp -R redis-check-aof /usr/local/redis/

cp -R redis-check-rdb /usr/local/redis/

cp -R redis-benchmark /usr/local/redis/

cp -R redis-sentinel  /usr/local/redis/
  • 4.2 创建用户
创建一个不能登陆的用户redis

useradd -s /sbin/nologin redis
  • 4.3 修改配置
#绑定本地地址

bind 127.0.0.1

#保护模式

protected-mode yes

#后台进程模式

daemonize yes

#添加密码

requirepass 963147825

#重命名一些高危命令

rename-command CONFIG ""

rename-command FLUSHALL ""

rename-command EVAL ""
  • 4.4 启动脚本
#!/bin/bash

sudo -u redis /usr/local/redis/redis-server /webserver/redis/redis.conf

通过redis用户运行redis程序

相关推荐

最全的MySQL总结,助你向阿里“开炮”(面试题+笔记+思维图)

前言作为一名编程人员,对MySQL一定不会陌生,尤其是互联网行业,对MySQL的使用是比较多的。对于求职者来说,MySQL又是面试中一定会问到的重点,很多人拥有大厂梦,却因为MySQL败下阵来。实际上...

Redis数据库从入门到精通(redis数据库设计)

目录一、常见的非关系型数据库NOSQL分类二、了解Redis三、Redis的单节点安装教程四、Redis的常用命令1、Help帮助命令2、SET命令3、过期命令4、查找键命令5、操作键命令6、GET命...

netcore 急速接入第三方登录,不看后悔

新年新气象,趁着新年的喜庆,肝了十来天,终于发了第一版,希望大家喜欢。如果有不喜欢看文字的童鞋,可以直接看下面的地址体验一下:https://oauthlogin.net/前言此次带来得这个小项目是...

精选 30 个 C++ 面试题(含解析)(c++面试题和答案汇总)

大家好,我是柠檬哥,专注编程知识分享。欢迎关注@程序员柠檬橙,编程路上不迷路,私信发送以下关键字获取编程资源:发送1024打包下载10个G编程资源学习资料发送001获取阿里大神LeetCode...

Oracle 12c系列(一)|多租户容器数据库

作者杨禹航出品沃趣技术Oracle12.1发布至今已有多年,但国内Oracle12C的用户并不多,随着12.2在去年的发布,选择安装Oracle12c的客户量明显增加,在接下来的几年中,Or...

flutter系列之:UI layout简介(flutter-ui-nice)

简介对于一个前端框架来说,除了各个组件之外,最重要的就是将这些组件进行连接的布局了。布局的英文名叫做layout,就是用来描述如何将组件进行摆放的一个约束。在flutter中,基本上所有的对象都是wi...

Flutter 分页功能表格控件(flutter 列表)

老孟导读:前2天有读者问到是否有带分页功能的表格控件,今天分页功能的表格控件详细解析来来。PaginatedDataTablePaginatedDataTable是一个带分页功能的DataTable,...

Flutter | 使用BottomNavigationBar快速构建底部导航

平时我们在使用app时经常会看到底部导航栏,而在flutter中它的实现也较为简单.需要用到的组件:BottomNavigationBar导航栏的主体BottomNavigationBarI...

Android中的数据库和本地存储在Flutter中是怎样实现的

如何使用SharedPreferences?在Android中,你可以使用SharedPreferencesAPI来存储少量的键值对。在Flutter中,使用Shared_Pref...

Flet,一个Flutter应用的实用Python库!

▼Flet:用Python轻松构建跨平台应用!在纷繁复杂的Python框架中,Flet宛如一缕清风,为开发者带来极致的跨平台应用开发体验。它用最简单的Python代码,帮你实现移动端、桌面端...

flutter系列之:做一个图像滤镜(flutter photo)

简介很多时候,我们需要一些特效功能,比如给图片做个滤镜什么的,如果是h5页面,那么我们可以很容易的通过css滤镜来实现这个功能。那么如果在flutter中,如果要实现这样的滤镜功能应该怎么处理呢?一起...

flutter软件开发笔记20-flutter web开发

flutterweb开发优势比较多,采用统一的语言,就能开发不同类型的软件,在web开发中,特别是后台式软件中,相比传统的html5开发,更高效,有点像c++编程的方式,把web设计出来了。一...

Flutter实战-请求封装(五)之设置抓包Proxy

用了两年的flutter,有了一些心得,不虚头巴脑,只求实战有用,以供学习或使用flutter的小伙伴参考,学习尚浅,如有不正确的地方还望各路大神指正,以免误人子弟,在此拜谢~(原创不易,转发请标注来...

为什么不在 Flutter 中使用全局变量来管理状态

我相信没有人用全局变量来管理Flutter应用程序的状态。毫无疑问,我们的Flutter应用程序需要状态管理包或Flutter的基本小部件(例如InheritedWidget或St...

Flutter 攻略(Dart基本数据类型,变量 整理 2)

代码运行从main方法开始voidmain(){print("hellodart");}变量与常量var声明变量未初始化变量为nullvarc;//未初始化print(c)...