环境:2台服务器,nginx、php和wordpress一台服务器,mysql一台服务器
mysql服务器
本实验以版本10.4.12为例
下载安装包
https://downloads.mariadb.org/mariadb/+releases/
解压安装包以
tar xvf mariadb-10.4.12.tar.gz
创建mysql目录
mkdir /data/mysql
创建系统用户并指定家目录
useradd -r -s /sbin/nologin -d /data/mysql mysql
修改mysql目录权限
chown mysql:mysql /data/mysql
安装依赖
yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boostdevel gcc gcc-c++ cmake ncurses ncurses-devel gnutls-devel libxml2-devel openssl openssldevel libevent-devel libaio-devel git
编译安装
cd mariadb-10.4.12
cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make -j 4 && make install
提示:如果出错,执行 rm -f CMakeCache.txt
复制MariaDB配置文件到/etc目录
cp /app/mysql/support-files/wsrep.cnf /etc/my.cnf
生成数据库文件
cd /app/mysql/
scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql
准备启动脚本
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
添加到开机启动并启动服务
chkconfig --add mysqld;chkconfig mysqld on;service mysqld start
准备客户端环境变量
echo 'PATH=/app/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
安全初始化
/app/mysql/bin/mysql_secure_installation
nginx/php服务器
编译安装nginx
地址:http://nginx.org/en/download.html
安装
yum install gcc pcre-devel openssl-devel zlib-devel
useradd -r -s /sbin/nologin nginx
./configure --prefix=/apps/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
make && make install
创建软链接
ln -s /apps/nginx/sbin/nginx /usr/sbin/
设置开机启动
vi /etc/rc.d/rc.local
/usr/sbin/nginx
chmod +x /etc/rc.d/rc.local
fpm方式编译安装php-7.3.5
yum install libxml2-devel bzip2-devel libmcrypt-devel (epel)
tar xvf php-7.3.18.tar.xz
cd php-7.3.18
./configure --prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
make && make install
配置
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd /app/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
service php-fpm start
配置nginx支持php
vi /apps/nginx/conf/conf.d/test.conf
charset utf-8;
server_tokens off;
server {
listen 80;
server_name www.x.com;
root /data/php;
location ~* \.php$ {
root /data/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
安装WordPress
官网:https://cn.wordpress.org/
解压缩WordPress博客程序到网页站点目录下
unzip wordpress-5.0.zip
在数据库服务器新建wpdb库和wpuser用户
mysql> create database wpdb;
mysql> grant all privileges on wpdb.* to wpuser@'%' identified by "密码";
设置执行权限
setfacl -R -m u:nginx:rwx wordpress
打开http://www.x.com/wordpress进行页面安装