您好,登錄后才能下訂單哦!
這篇文章主要介紹“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#<center>nginx</center>#<center>Apache</center>#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.php <?php // Zabbix GUI configuration file. global $DB; $DB['TYPE'] = 'MYSQL'; $DB['SERVER'] = 'localhost'; $DB['PORT'] = '0'; $DB['DATABASE'] = 'zabbix'; $DB['USER'] = 'zabbix'; $DB['PASSWORD'] = 'zabbix.localhost'; // Schema name. Used for IBM DB2 and PostgreSQL. $DB['SCHEMA'] = ''; $ZBX_SERVER = 'localhost'; $ZBX_SERVER_PORT = '10051'; $ZBX_SERVER_NAME = ''; $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
QA:
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的過程”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。