标签:9.4 lex index.php host prevent select 密码 用户 安装nginx
1.安装zabbix2.安装nginx
#!/bin/bash
#author:panpeng
#此脚本用于安装nginx
#配置yum源并安装依赖包
yum -y install pcre-devel openssl-devel
#跳转文件夹
cd /myroles/roles/nginx/files/lnmp
#安装nginx
tar xf nginx-1.13.12.tar.gz -C /usr/src
cd /usr/src/nginx-1.13.12
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
#创建系统用户
useradd -M -s /sbin/nologin www
#创建链接
ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
#启动
cat > /lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable nginx.service
systemctl start nginx.service
2.1配置文件nginx.conf ---- 此处有坑$document_root$fastcgi_script_name;这个变量请注意
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;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass {{ansible_all_ipv4_addresses[0]}}:9000; #playbook ,template,如果不为ansible,则直
接php主机ip
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
3.安装php --- 此处用的端口和ip用的127.0.0.1:9000可根据需要修改,相应更改nginx.conf
#!/bin/bash
#跳转相应文件夹
cd /myroles/roles/nginx/files
#安装php7
tar -zxvf php-7.2.7.tar.gz -C /usr/src/
cd /usr/src/php-7.2.7
#安装依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
#编译配置。如果按照我的步骤一步步来,应该一步到位,直接看见 Thank you for using PHP。如果报错,基本就是相关依赖未安装完全。
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
#编译安装
make && make install
#添加 PHP 命令到环境变量
echo "export PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin" >> /etc/profile
#立即生效
source /etc/profile
#配置php-fpm
/usr/bin/cp php.ini-production /etc/php.ini
/usr/bin/cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
/usr/bin/cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
/usr/bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
#添加php-fpm至服务列表并设置开机自启。
chkconfig --add php-fpm
#chkconfig --list php-fpm
chkconfig php-fpm on
#创建用户www
useradd -M -s /sbin/nologin www
#启动php-fpm
/etc/init.d/php-fpm start
#php安装完成
4.安装mysql
#!/bin/bash
#author:pan
#切换到相应文件夹
cd
#二进制安装mysql5.7.20
tar xvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local/
mv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql
cd /usr/local/mysql/
mkdir -p data log binlogs run
cd /usr/local/
#添加用户
useradd -M -s /sbin/nologin mysql
#更改属主
chown -R mysql.mysql mysql
#添加路径
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
#删除原my.cnf
rm -f /etc/my.cnf
#创建my.cnf
cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535
skip-name-resolve
lower_case_table_names=1
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=‘SET NAMES utf8mb4‘
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 2048M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
key_buffer_size = 64M
log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/binlogs/mysql-bin
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 0
query_cache_size = 0
server-id=1
EOF
#初始化数据库
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#设置启动项
cat > /usr/lib/systemd/system/mysqld.service << EOF
#Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
##This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; version 2 of the License.
##This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
##You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##systemd service file for MySQL forking server
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/usr/local/mysql/run/mysqld.pid
#Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
#Execute pre and post scripts as root
PermissionsStartOnly=true
#Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd
#Start main service
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/run/mysqld.pid $MYSQLD_OPTS
#Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
#Sets open_files_limit
LimitNOFILE = 65535
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
EOF
#重新加载daemon
systemctl daemon-reload
systemctl enable mysqld.service
systemctl start mysqld
#启动后第一次登陆密码
#grep ‘temporary password‘ /usr/local/mysql/log/mysql_error.log
#修改初始密码
#mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘000000‘;
#安装完成
5.修改php.ini的参数
[root@localhost php-5.6.30]# cat -n /etc/php.ini | sed -n ‘383p;393p;404p;672p;702p;825p;939p‘
383 max_execution_time = 300
393 max_input_time = 300
404 memory_limit = 256M
672 post_max_size = 32M
702 always_populate_raw_post_data = -1 #5.6以后无此条,7.2.7没这一条了
825 upload_max_filesize = 16M
939 date.timezone = Asia/Shanghai
[root@localhost etc]# cat -n /usr/local/php/etc/php-fpm.d/www.conf | sed -n ‘23p;24p‘
23 user = www
24 group = www
6.安装zabbix server端
[root@localhost ~]# useradd zabbix -s /sbin/nologin -M
[root@localhost ~]# tar xf zabbix-3.2.11.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/zabbix-3.2.11/
[root@localhost zabbix-3.2.11]# ./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --with-libxml2
[root@localhost zabbix-3.2.11]# make && make install
由于zabbix启动脚本路径默认指向的是/usr/local/sbin路径,因此,需要提前简历软连接:
[root@localhost zabbix-3.2.11]# ln -s /usr/local/zabbix/sbin/ /usr/local/sbin/
[root@localhost zabbix-3.2.11]# ln -s /usr/local/zabbix/bin/ /usr/local/bin/
7.配置zabbix的mysql环境
7.1[root@localhost local]# mysql -uroot -p000000
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)
#mysql> grant all privileges on zabbix. to zabbix@‘192.168.%.%‘ identified by ‘000000‘;
#Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> grant all privileges on zabbix. to zabbix@‘localhost‘ identified by ‘000000‘;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> select user,host from mysql.user;
+---------------+-------------+
| user | host |
+---------------+-------------+
| wp | 192.168.%.% |
| zabbix | 192.168.%.% |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-------------+
5 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> create database zabbix;
mysql> use zabbix;
7.2如下数据的导入顺序不可以错
mysql> source /usr/src/zabbix-3.2.11/database/mysql/schema.sql
mysql> source /usr/src/zabbix-3.2.11/database/mysql/images.sql
mysql> source /usr/src/zabbix-3.2.11/database/mysql/data.sql
8.复制zabbix web目录到nginx web根目录下
[root@localhost ~]# cp -pr /usr/src/zabbix-3.2.11/frontends/php/ /usr/local/nginx/html/zabbix
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# ls -l
drwxr-xr-x 2 root root 57 Jul 25 05:19 tmp
drwxr-xr-x 5 www www 4096 Jul 25 05:28 wordpress
drwxr-xr-x 13 mysql mysql 4096 Dec 27 2017 zabbix
[root@localhost html]# chown -R www.www zabbix
[root@localhost html]# ll -d zabbix/
drwxr-xr-x. 13 www www 4096 Feb 27 2017 zabbix/
9.登录web根据提示生成zabbix.conf.php配置文件
#起初并没有zabbix.conf.php配置文件,我们可以选择自动生成配置文件
[root@localhost ~]# cd /usr/local/nginx/html/zabbix/conf
9.1 访问 http://192.168.9.20/zabbix/setup.php
9.2安装zabbix3.2.11时 PHP ldap Warning ,解决LDAP问题
[root@localhost sbin]# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
total 5424
-rwxr-xr-x 1 root root 3578956 Jul 24 21:35 opcache.a
-rwxr-xr-x 1 root root 1970256 Jul 24 21:35 opcache.so
[root@localhost sbin]# cd /usr/src/php-7.2.7/ext/ldap
[root@localhost ldap]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
[root@localhost ldap]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap #编译
[root@localhost ldap]# make && make install
我操作时编译出现问题提示无ladp.h文件,解决办法
[root@localhost ldap]# yum install openldap
[root@localhost ldap]# yum install openldap-devel
[root@localhost ldap]# cp -frp /usr/lib64/libldap* /usr/lib/
查看
[root@localhost ldap]# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
total 5624
-rwxr-xr-x 1 root root 201440 Jul 25 08:08 ldap.so
-rwxr-xr-x 1 root root 3578956 Jul 24 21:35 opcache.a
-rwxr-xr-x 1 root root 1970256 Jul 24 21:35 opcache.so
在php.ini配置中添加模块
[root@localhost ldap]# vim /etc/php.ini
869 extension=ldap.so #新添加模块
[root@localhost ldap]# pkill php-fpm
[root@localhost ldap]# cd /usr/local/php/sbin/
[root@localhost sbin]# ./php-fpm
9.3刷新网页
9.4连接数据库
9.5登陆页面
用户名:Admin 注A大写
密码:zabbix
9.6 进入管理页面
9.7查看我们生成的配置文件
[root@localhost ldap]# cat /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;
$DB[‘TYPE‘] = ‘MYSQL‘;
$DB[‘SERVER‘] = ‘192.168.9.20‘;
$DB[‘PORT‘] = ‘0‘;
$DB[‘DATABASE‘] = ‘zabbix‘;
$DB[‘USER‘] = ‘zabbix‘;
$DB[‘PASSWORD‘] = ‘000000‘;
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB[‘SCHEMA‘] = ‘‘;
$ZBX_SERVER = ‘localhost‘;
$ZBX_SERVER_PORT = ‘10051‘;
$ZBX_SERVER_NAME = ‘zabbix‘;
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
10.修改zabbix-server服务配置文件
标签:9.4 lex index.php host prevent select 密码 用户 安装nginx
原文地址:http://blog.51cto.com/13893093/2177505