重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍“CentOS下安装配置nginx、MySQL以及zabbix的过程”,在日常操作中,相信很多人在CentOS下安装配置nginx、mysql以及zabbix的过程问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”CentOS下安装配置nginx、mysql以及zabbix的过程”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了青山免费建站欢迎大家使用!
环境:
操作系统:CentOS 6.8 x86_64(关闭SELinux、iptables)
Nginx:1.10.1
PHP: 7.0.10
MySQL:5.7.13
Zabbix:3.0.4
一.安装MySQL
1.安装依赖
yum -y install gcc gcc-devel gcc-c++ gcc-c++-devel libaio-devel boost boost-devel autoconf* automake* zlib* libxml* ncurses-devel ncurses libgcrypt* libtool* cmake openssl openssl-devel bison bison-devel unzip numactl-devel net-snmp-devel net-snmp-utils
2.卸载mysql-libs,否则下面安装mysql的时候会报错
rpm -e --nodeps mysql-libs
3.下载解压及安装
wget tar xf mysql-5.7.13-1.el6.x86_64.rpm-bundle.tar rpm -ivh `ls |grep mysql-community|grep -v test`
4.由于mysql 5.7跟之前的5.6安全性有很大提升,有很多地方是不一样的
先重置密码
#修改默认字符集 sed -i '/\[mysqld\]/a\character-set-server=utf8' my.cnf #启动mysqld,并进行初始化 /etc/init.d/mysqld start #停止mysqld,以便进行无密码启动 /etc/init.d/mysqld stop #无密码启动mysql mysqld_safe --skip-grant-tables & mysql #注意新版的mysql 5.7在mysql.user表下已经没有password字段了 mysql> update mysql.user set authentication_string=password('123456.abcd') where user='root' and Host = 'localhost'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements #会被告知你的密码不符合当前策略 #修改对应的密码策略,但是密码也至少为9位 mysql> set global validate_password_policy=0; mysql> update mysql.user set authentication_string=password('123456.abcd') where user='root' and Host = 'localhost'; service mysqld restart
二.编译安装PHP 7.0.10
1.安装EPEL源及安装对应的依赖包
rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm yum -y install libmcrypt-devel mcrypt mhash gd-devel ncurses-devel libxml2-devel bzip2-devel libcurl-devel curl-devel libjpeg-devel libpng-devel freetype-devel net-snmp-devel openssl-devel
2.安装libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv1.14 make && make install cd ..
3.下载及编译php
wget http://cn2.php.net/get/php-7.0.10.tar.gz/from/this/mirror tar zxf mirror cd php-7.0.10/ ./configure --prefix=/usr/local/php7.0.10 --with-config-file-path=/usr/local/php7.0.10/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv1.14 --with-pcre-regex --with-zlib --with-bz2 --enable-calendar --with-curl --enable-dba --with-libxml-dir --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --with-mhash --enable-mbstring --with-mcrypt --enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip --enable-bcmath --with-snmp --disable-ipv6 --with-gettext --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-openssl #注意不能有--enable-gd-jis-conv参数,否则后面图形乱码 make && make install
4.修改相应参数
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm cp /usr/local/php7.1.0/etc/php-fpm.conf.default /usr/local/php7.1.0/etc/php-fpm.conf cp php.ini-production /usr/local/php7.0.10/etc/php.ini #修改时区 sed -i 's#;date.timezone =#date.timezone = PRC#g' /usr/local/php7.0.10/etc/php.ini #隐藏PHP版本 sed -i 's#expose_php = On#expose_php = Off#g' /usr/local/php7.0.10/etc/php.ini cp /usr/local/php7.0.10/etc/php-fpm.d/www.conf.default /usr/local/php7.0.10/etc/php-fpm.d/www.conf sed -i 's#;rlimit_files = 1024#rlimit_files = 65535#g' /usr/local/php7.0.10/etc/php-fpm.d/www.conf sed -i 's#;listen.owner = www#listen.owner = www#g' /usr/local/php7.0.10/etc/php-fpm.d/www.conf sed -i 's#;listen.group = www#listen.group = www#g' /usr/local/php7.0.10/etc/php-fpm.d/www.conf sed -i 's#;listen.mode = 0660#listen.mode = 0660#g' /usr/local/php7.0.10/etc/php-fpm.d/www.conf sed -i 's#listen = 127.0.0.1:9000#;listen = 127.0.0.1:9000#g' /usr/local/php7.0.10/etc/php-fpm.d/www.conf sed -i '/;listen = 127.0.0.1:9000/a\listen = /tmp/php-fpm.sock' /usr/local/php7.0.10/etc/php-fpm.d/www.conf #安全配置,禁用相关函数,注意不能包含scandir和fsockopen,zabbix需要使用到这2个函数 sed -i 's#^;cgi.fix_pathinfo=1#cgi.fix_pathinfo=0#g' /usr/local/php7.0.10/etc/php.ini sed -i 's#disable_functions =#disable_functions =exec,system,eval,passthru,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,fsocket,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server#g' /usr/local/php7.0.10/etc/php.ini #限制执行目录,我的WEB目录都在/var/www/html下 sed -i 's#;open_basedir =#open_basedir = "/var/www/html/:/tmp/"#g' /usr/local/php7.0.10/etc/php.ini #修改PHP相关参数以保证zabbix最低要求 sed -i 's#max_execution_time = 30#max_execution_time = 300#g' /usr/local/php7.0.10/etc/php.ini sed -i 's#max_input_time = 60#max_input_time = 300#g' /usr/local/php7.0.10/etc/php.ini sed -i 's#post_max_size = 8M#post_max_size = 24M#g' /usr/local/php7.0.10/etc/php.ini sed -i 's#upload_max_filesize = 2M#upload_max_filesize = 4M#g' /usr/local/php7.0.10/etc/php.ini #修改php连接mysql sed -i 's#pdo_mysql.default_socket=#pdo_mysql.default_socket= /var/lib/mysql/mysql.sock#g' /usr/local/php7.0.10/etc/php.ini sed -i 's#mysqli.default_socket =#mysqli.default_socket = /var/lib/mysql/mysql.sock#g' /usr/local/php7.0.10/etc/php.ini 增加PHP执行用户 groupadd -g 10080 www useradd -g www -u 10080 -s /sbin/nologin -d /dev/null www
三.安装Nginx
1.下载及安装nginx
wget http://nginx.org/download/nginx-1.10.1.tar.gz tar zxf nginx-1.10.1.tar.gz cd nginx-1.10.1 #隐藏Nginx版本 sed -i 's#1.10.1#2.2.14.0#g' src/core/nginx.h sed -i 's#"nginx/"#"Apache/"#g' src/core/nginx.h sed -i 's#"Server: nginx"#"Server: Apache"#g' src/http/ngx_http_header_filter_module.c sed -i 's#nginx #Apache #g' src/http/ngx_http_special_response.c ./configure --prefix=/usr/local/nginx1.10.1 --user=www --group=www --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module make && make install sed -i 's#nginx/$nginx_version;#Apache/$nginx_version;#g' /usr/local/nginx1.10.1/conf/fastcgi.conf
2.配置Nginx
vim /usr/local/nginx1.10.1/conf/nginx.conf user www www; worker_processes 4; error_log logs/error.log; pid logs/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_param HTTP_PROXY ""; #隐藏后端服务器的相关参数 proxy_hide_header X-Powered-By; proxy_hide_header X-Forwarded-For; proxy_hide_header X-AspNet-Version; proxy_hide_header X-AspNetMvc-Version; proxy_hide_header Via; proxy_hide_header X-Varnish; proxy_hide_header Server; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 5; gzip_disable "MSIE [1-6]\."; gzip_types text/plain text/css text/xml application/javascript application/x-javascript; gzip_vary on; include host/*.conf; }
3.配置站点
mkdir /usr/local/nginx1.10.1/conf/host vim /usr/local/nginx1.10.1/conf/host/zabbix.conf server { listen 80; server_name localhost zabbix; location / { root /var/www/html; index index.html index.htm index.php; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { fastcgi_pass unix:/tmp/php-fpm.sock; fastcgi_index index.php; fastcgi_param HTTP_PROXY ""; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
四.安装Zabbix
1.下载及安装zabbix
yum -y install OpenIPMI-devel wget http://120.52.73.47/nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz tar -zxvf zabbix-3.0.4.tar.gz cd zabbix-3.0.4 ./configure --prefix=/usr/local/zabbix3.0.4 --enable-server --with-mysql --with-net-snmp --with-libxml2 --with-libcurl --with-openipmi --enable-agent make && make installl
2.配置zabbix
cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/ cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/ sed -i 's#/usr/local/sbin/zabbix_server#/usr/local/zabbix3.0.4/sbin/zabbix_server#g' /etc/init.d/zabbix_server sed -i 's#/usr/local/sbin/zabbix_agentd#/usr/local/zabbix3.0.4/sbin/zabbix_agentd#g' /etc/init.d/zabbix_agentd
3.复制WEB站点
mkdir /var/www/html/zabbix cp -rf frontends/php/* /var/www/html/zabbix
4.zabbix乱码图形处理
将Windows操作系统的C:\Windows\Fonts\simkai.ttf字体文件上传至/var/www/html/zabbix/font。防止出现乱码情况
sed -i 's#DejaVuSans#simkai#g' /var/www/html/zabbix/include/defines.inc.php
5.使用MySQL创建zabbix数据库并授权
mysql -uroot -p mysql> create database zabbix character set utf8; mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix.localhost';
6.导入数据库
进入zabbix-3.0.4源码文件目录 mysql -uroot -p zabbix < database/mysql/schema.sql mysql -uroot -p zabbix < database/mysql/data.sql mysql -uroot -p zabbix < database/mysql/p_w_picpaths.sql
7.修改zabbix_server配置文件,以下是我的配置文件
egrep -v '^:|^#' /usr/local/zabbix3.0.4/etc/zabbix_server.conf|awk 'NF>0' LogFile=/tmp/zabbix_server.log DBName=zabbix DBUser=zabbix DBPassword=zabbix.localhost StartPollers=10 StartPingers=4 StartDiscoverers=4 JavaGateway=127.0.0.1 JavaGatewayPort=10052 StartJavaPollers=5 StartVMwareCollectors=5 VMwareFrequency=60 VMwareCacheSize=8M
8.再修改zabbix web目录下的配置文件
vim /var/www/html/zabbix3.0.4/conf/zabbix.conf.phpQA:
1.zabbix乱码问题
a.数据库字符集问题,创建数据库时指定字符集
create database zabbix character set utf8;
b.未上传中文字体,或者未修改include/define.inc.php文件
c.编译PHP时携带有--enable-gd-jis-conv参数,如果带有这个参数,画图的时候出现
2.php7安装memcache问题
git clone cd pecl-memcache /usr/local/php7.0.10/bin/phpize ./configure --with-php-config=/usr/local/php7.0.10/bin/php-config make && make install echo 'extension = "memcache.so"'>>/usr/local/php7.0.10/etc/php.ini #检查php是否加载memcache模块 /usr/local/php7.0.10/bin/php -m |grep memcache #重启php-fpm服务以加载memcache模块 /etc/init.d/php-fpm restart到此,关于“CentOS下安装配置nginx、mysql以及zabbix的过程”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!
当前题目:CentOS下安装配置nginx、mysql以及zabbix的过程
网站URL:http://cqcxhl.cn/article/pgsjso.html