文章都可以转载、引用,标明转载出处即可。

linux 安装nginx+php7+MariaDB 10.1

DBserver Mr.c 1840℃ 0评论

之前写过一篇安装php5.6环境的文章,但是优化做的不好,并不是适用,最近新整理了下,部署php7 环境,另外数据库尝试使用MySQL 的分支版本MariaDB
相关说明:

系统环境:centos 7.0
nginx/1.10.1
MariaDB 10.1.18
PHP 7.0.11 (cli)
nginx 通过sock 方式调用php ,php开启缓存(OPcache)

对应扩展组件说明:
nginx需要安装pcre 和openssl 扩展包
php需要安装libiconv,curl ,libmcrypt ,mhash ,mcrypt 这几个扩展包
MariaDB为了优化内存可以安装tcmalloc 工具,软件包为gperftools-2.5
相关软件的下载链接如下:
nginx下载:http://nginx.org/download/nginx-1.10.1.tar.gz
php7下载:http://cn2.php.net/distributions/php-7.0.11.tar.gz
MariaDB下载:https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.1.18/source/mariadb-10.1.18.tar.gz
工具扩展包下载不是很方便,为了便于管理,上传到了百度网盘上http://pan.baidu.com/s/1o8IsF6U

一:安装前准备工作:

 1.关闭selinux

临时关闭:setenforce 0
永久关闭:
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq 保存,建议先临时关闭,然后再修改配置文件,因为修改配置需要重启才能生效。

 2.安装必要的依赖包

yum -y install deltarpm gcc gcc-c++ make cmake autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libaio readline-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel libxslt-devel libicu-devel libevent-devel libtool libtool-ltdl bison gd-devel vim-enhanced pcre-devel zip unzip ntpdate sysstat patch bc expect rsync git lsof lrzsz

二:安装mariadb数据库

 1.安装tcmalloc 内存优化工具

[root@aliyun pro]#tar xzf gperftools-2.5.tar.gz
[root@aliyun pro]#cd gperftools-2.5
[root@aliyun gperftools]#./configure --enable-frame-pointers
[root@aliyun gperftools]#make && make install
[root@aliyun gperftools]#echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
[root@aliyun gperftools]#ldconfig

 2.如果服务器的内存低于2GB 那么请先增加swap分区,1G 内存无法安装MariaDB10.1 ,我的服务器默认没有设置swap分区,所以增加了1G的swap分区

[root@aliyun pro]#dd if=/dev/zero of=/swapfile count=1024 bs=1M
[root@aliyun pro]#mkswap /swapfile
[root@aliyun pro]#swapon /swapfile
[root@aliyun pro]#chmod 600 /swapfile
[root@aliyun pro]#echo '/swapfile    swap    swap    defaults    0 0' >> /etc/fstab

 3.创建运行账户以及安装目录,data目录

[root@aliyun pro]#useradd -M -s /sbin/nologin mysql
[root@aliyun pro]#mkdir -p /usr/local/mariadb
[root@aliyun pro]#mkdir -p /home/mariadb
[root@aliyun pro]#chown mysql.mysql -R /home/mariadb/

 4.开始安装MariaDB

[root@aliyun pro]#tar zxvf mariadb-10.1.18.tar.gz
[root@aliyun pro]#cd mariadb-10.1.18
[root@aliyun mariadb-10.1.18]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb/ \
    -DMYSQL_DATADIR=/home/mariadb/ \
    -DSYSCONFDIR=/etc \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_EMBEDDED_SERVER=1 \
    -DENABLE_DTRACE=0 \
    -DENABLED_LOCAL_INFILE=1 \
    -DDEFAULT_CHARSET=utf8mb4 \
    -DDEFAULT_COLLATION=utf8mb4_general_ci \
    -DEXTRA_CHARSETS=all \
    -DCMAKE_EXE_LINKER_FLAGS='-ltcmalloc'   #如果不安装内存优化,该句省略
make && make install 

一开始在make install 的过程中出现了报错:

g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report 
........
按照第2点增加swap分区然后重新安装即可

 5.配置服务文件和my.cnf

[root@aliyun mariadb-10.1.18]#cp support-files/mysql.server /etc/init.d/mysqld
[root@aliyun mariadb-10.1.18]#sed -i "s@^basedir=.*@basedir=/usr/local/mariadb/@" /etc/init.d/mysqld
[root@aliyun mariadb-10.1.18]#sed -i "s@^datadir=.*@datadir=/home/mariadb/@" /etc/init.d/mysqld
[root@aliyun mariadb-10.1.18]#chmod 755 /etc/init.d/mysqld
[root@aliyun mariadb-10.1.18]#chkconfig --add mysqld
[root@aliyun mariadb-10.1.18]#chkconfig mysqld on
#my.cnf中的配置需要根据服务器性能进行调整,该配置适合1G内存服务器
[root@aliyun mariadb-10.1.18]#cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysqld]
port = 3306
socket = /tmp/mysql.sock

basedir = /usr/local/mariadb/
datadir = /home/mariadb/
pid-file = /home/mariadb/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1

init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4

skip-name-resolve
#skip-networking
back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
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

log_error = /home/mariadb/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /home/mariadb/mysql-slow.log

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

[mysqldump]
quick
max_allowed_packet = 500M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF

 6.初始化数据库、设置密码等

#初始化数据库,设置环境变量
[root@aliyun mariadb-10.1.18]#/usr/local/mariadb/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/home/mariadb/
[root@aliyun mariadb-10.1.18]#echo "export PATH=/usr/local/mariadb/bin:\$PATH" >> /etc/profile
[root@aliyun mariadb-10.1.18]#source  /etc/profile
[root@aliyun mariadb-10.1.18]#service mysqld start
#定义数据库密码等
[root@aliyun mariadb-10.1.18]#mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by 'cnyunwei' with grant option;"
[root@aliyun mariadb-10.1.18]#mysql -e "grant all privileges on *.* to root@'localhost' identified by 'cnyunwei' with grant option;"
[root@aliyun mariadb-10.1.18]#mysql -uroot -pcnyunwei -e "delete from mysql.user where Password='';"
[root@aliyun mariadb-10.1.18]#mysql -uroot -pcnyunwei -e "delete from mysql.db where User='';"
[root@aliyun mariadb-10.1.18]#mysql -uroot -pcnyunwei -e "delete from mysql.proxies_priv where Host!='localhost';"
[root@aliyun mariadb-10.1.18]#mysql -uroot -pcnyunwei -e "drop database test;"
[root@aliyun mariadb-10.1.18]#mysql -uroot -pcnyunwei -e "reset master;"
#设置数据库连接
[root@aliyun mariadb-10.1.18]#rm -rf /etc/ld.so.conf.d/mariadb-x86_64.conf
[root@aliyun mariadb-10.1.18]#echo "/usr/local/mariadb/lib" > /etc/ld.so.conf.d/mariadb.conf
[root@aliyun mariadb-10.1.18]#ldconfig
[root@aliyun mariadb-10.1.18]#service mysqld stop

博文过长,在此进行切割,请移步下一篇《linux 安装nginx+php7+MariaDB 10.1 之php 安装》

转载请注明:菜鸟运维 » linux 安装nginx+php7+MariaDB 10.1

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(1)个小伙伴在吐槽
  1. MariaDB的效率确实比MySQL 更强
    nando2016-11-04 10:02 回复