CentOS私有云主机部署LNMP架构
接上一篇Docker构建CentOS私有云主机,接下来我在私有云主机上部署lnmp架构,这篇的内容在后面的dockerfile制作中会更加方便,这里仅仅做个示例。
1)根据如上的Docker构建CentOS云主机,CentOS8云主机创建成功,通过CRT远程登录22端口,如图所示:
(1)全新运行一个容器
docker run -itd --privileged --name xqy_centos02 -p 6000:22 -p 8090:80 xqy_centos8.1:ssh_lnmp
[root@hecs-x-medium-2-linux-20200611091300 ~]# docker run -itd --privileged --name xqy_centos02 -p 6000:22 -p 8090:80 xqy_centos8.1:ssh_lnmp
c419f4fc45f88d90e9fab749c491e25db2bea0736e7c83674340f859a0d2935f
[root@hecs-x-medium-2-linux-20200611091300 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c419f4fc45f8 xqy_centos8.1:ssh_lnmp "/bin/bash" 4 seconds ago Up 3 seconds 0.0.0.0:6000->22/tcp, 0.0.0.0:8090->80/tcp xqy_centos02
0e18294d2044 centos:latest "/bin/bash" 23 hours ago Up 23 hours xqy_centos01
87cde75bcd91 registry:latest "/entrypoint.sh /etc…" 12 days ago Up 12 days 0.0.0.0:5000->5000/tcp xuqy_registry
338b541e76c5 nginx "/docker-entrypoint.…" 12 days ago Up 12 days 80/tcp my_nginx
[root@hecs-x-medium-2-linux-20200611091300 ~]#
(2)运行sshd
[root@c419f4fc45f8 /]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
[root@c419f4fc45f8 /]# /usr/sbin/sshd
[root@c419f4fc45f8 /]#
2)基于CentOS7云主机工具连接构建LNMP WEB(Linux+Nginx+MYSQL+PHP)平台,并且发布Discuz门户网站,操作的步骤和方法如下:
(1)Nginx安装配置
yum -y install wget gcc-c++ gzip tar make pcre pcre-devel zlib-devel openssl openssl-devel
wget -c http://nginx.org/download/nginx-1.16.0.tar.gz
tar -xzf nginx-1.16.0.tar.gz
cd nginx-1.16.0
useradd -s /sbin/nologin www -M;./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
预编译成功如图
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
编译如图
objs/src/http/modules/ngx_http_upstream_keepalive_module.o \
objs/src/http/modules/ngx_http_upstream_zone_module.o \
objs/src/http/modules/ngx_http_stub_status_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory '/root/nginx-1.16.0'
[root@c419f4fc45f8 nginx-1.16.0]#
安装
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory '/root/nginx-1.16.0'
检查启动进程
[root@c419f4fc45f8 sbin]# ps -ef|grep nginx
root 6595 0 0 08:31 ? 00:00:00 nginx: master process ./nginx
www 6596 6595 0 08:31 ? 00:00:00 nginx: worker process
root 6598 36 0 08:31 pts/2 00:00:00 grep --color=auto nginx
(2)MYSQL安装配置
yum install -y gcc-c++ ncurses-devel cmake make perl gcc autoconf
yum install -y automake zlib libxml2 libxml2-devel libgcrypt libtool bison
wget -c http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.45.tar.gz
tar -xzf mysql-5.6.45.tar.gz
cd mysql-5.6.45
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql56/ \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BIG_TABLES=1 \
-DWITH_DEBUG=0
make
make install
#Config MYSQL Set System Service
cd /usr/local/mysql56/
\cp support-files/my-default.cnf /etc/my.cnf
\cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
service mysqld stop
mv /data/mysql/ /data/mysql.bak/
mkdir -p /data/mysql/
useradd mysql
/usr/local/mysql56/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql56/
ln -s /usr/local/mysql56/bin/* /usr/bin/
service mysqld restart
(3)PHP安装配置
yum install libxml2 libxml2-devel gzip bzip2 -y
wget -c http://mirrors.sohu.com/php/php-5.6.28.tar.bz2
tar jxf php-5.6.28.tar.bz2
cd php-5.6.28
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql56/
--enable-fpm
make
make install
#Config LNMP WEB and Start Server.
cp php.ini-development /usr/local/php5/etc/php.ini
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod o+x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
(4)Nginx配置文件配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}