搭建服务器lmnpr-linux_Mysql_nginx_php_redis

Posted 歆瑶的小房子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建服务器lmnpr-linux_Mysql_nginx_php_redis相关的知识,希望对你有一定的参考价值。

安装docker软件

国内镜像一键安装

yum -y install docker
注 :需要使用root用户来安装 进入root用户命令
su root

安装中出现以下错误

Error: docker-ce-cli conflicts with 2:docker-1.13.1-205.git7d71120.el7.centos.x86_64
Error: docker-ce conflicts with 2:docker-1.13.1-205.git7d71120.el7.centos.x86_64

需要运行卸载命令后再执行

yum remove -y docker-ce.x86_64
yum remove -y docker-ce-cli

配置docker 文件配置信息 

vim /etc/docker/daemon.json

"registry-mirrors":["https://ftnejmh3.mirror.aliyuncs.com"]


启动docker服务

service docker start 
service docker restart


拉取nginx镜像

搭建服务器lmnpr-linux_Mysql_nginx_php_redis_mysql

docker pull nginx

使用docker images 查看拉取状态

搭建服务器lmnpr-linux_Mysql_nginx_php_redis_mysql_02

创建nginx的配置文件

[root@localhost nginx]# cd /docker/nginx/
[root@localhost nginx]# touch default.conf
server 
listen 80;
listen [::]:80;
server_name localhost;
root /docker/www/lmrs-2008/public; //项目文件地址
index index.php index.html;
location /
try_files $uri $uri/ /index.php?$query_string;

error_page 500 502 503 504 /50x.html;
location = /50x.html
root /docker/www/lmrs-2008/public;

location ~ \\.php$
root /docker/www/lmrs-2008/public;
fastcgi_pass 172.17.0.3:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;


创建容器

docker run -p 80:80 -d --name nginx -v /docker/nginx/default.conf:/etc/nginx/conf.d/default.conf -v /docker/www:/docker/www --privileged=true nginx
创建php-fpm 镜像
docker pull php:7.4-fpm
创建容器
docker run -p 9000:9000 -d --name php -v /docker/www:/docker/www --privileged=true php:7.4-fpm
说明:-p 9000:9000 :将容器的9000端口映射到主机的9000端口
-d 后台运行(守护进程)
--name php:将容器命名为php
-v 将主机中当前目录下的www挂载到容器的www目录


搭建服务器lmnpr-linux_Mysql_nginx_php_redis_php_03


配置完成后需要查看

php-fpm 和nginx的ip地址是否一致
docker inspect php | grep "IPAddress"

"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.3",
"IPAddress": "172.17.0.3",


搭建服务器lmnpr-linux_Mysql_nginx_php_redis_php_04


搭建mysql


导入镜像docker pull mysql

搭建服务器lmnpr-linux_Mysql_nginx_php_redis_php_05


创建mysql 配置文件目录

[client]
port= 3306
socket= /tmp/mysql.sock
[mysqld]
secure_file_priv=/var/lib/mysql
port= 3306
socket= /tmp/mysql.sock
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 100G
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 4K
read_buffer_size = 768K
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
tmp_table_size = 32M
default_authentication_plugin = mysql_native_password
lower_case_table_names = 1
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
binlog_expire_logs_seconds = 600000
slow_query_log=1
slow-query-log-file=/usr/local/mysql/data/mysql-slow.log
long_query_time=3
early-plugin-load = ""
innodb_data_home_dir = /usr/local/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
innodb_buffer_pool_size = 128M
innodb_log_file_size = 64M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 1
innodb_write_io_threads = 1
[mysqldump]
quick
max_allowed_packet = 500M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout


创建容器

docker run -p 3306:3306 -d --name mysql -v /etc/my.cnf:/etc/mysql/my.cnf --privileged=true -e MYSQL_ROOT_PASSWORD=root mysql


显示以下内容说明容器创建成功

搭建服务器lmnpr-linux_Mysql_nginx_php_redis_mysql_06


进入mysql 配置一个个人用户 ,用于项目使用

mysql> create user `wangkuo`@`%` identified by "root";
Query OK, 0 rows affected (0.22 sec)

mysql> grant all on *.* to `wangkuo`@`%` with grant option;
Query OK, 0 rows affected (0.02 sec)

显示以下信息 则说明数据库配置成功


搭建服务器lmnpr-linux_Mysql_nginx_php_redis_mysql_07



系统关机后

sudo systemctl start docker           启动docker
docker ps -a 查看容器
docker start php
docker start nginx
docker start mysql


搭建服务器lmnpr-linux_Mysql_nginx_php_redis_docker_08





以上是关于搭建服务器lmnpr-linux_Mysql_nginx_php_redis的主要内容,如果未能解决你的问题,请参考以下文章

利用windows server 2008如何搭建web服务器

Threejs基础环境搭建(一)静态服务器

如何自己搭建openlayers地图服务器

Linux服务器搭建常用环境

如何在CentOS中搭建NTP服务器

怎么搭建本地SVN服务