发布时间:2017-12-11 13:26:19编辑:Run阅读(4798)
需要的一些包(所有的包都放在/opt目录下)
zabbix-3.4.4.tar.gz
boost_1_59_0.tar.gz
mysql-5.7.14.tar.gz
php-7.0.9.tar.gz
pcre-8.39.tar.gz
openssl-1.0.1t.tar.gz
zlib-1.2.8.tar.gz
tengine-2.2.1.tar.gz
msyh.ttf(字体文件-使用默认也行)
安装epel更新源(对应系统版本)
下载epel文件epel-release-latest-7.noarch.rpm
wget https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
安装
rpm -ivh epel-release-latest-7.noarch.rpm
安装编译环境
yum groupinstall -y "Development tools"
更新bash和openssl漏洞以及基本软件
yum install -y bash openssl* ntp vim wget telnet nscd
更新服务器时间
ntpdate ntp1.aliyun.com
优化系统
vim /etc/sysctl.conf
net.ipv4.tcp_mem = 3097431 4129911 6194862
net.ipv4.tcp_rmem = 4096 87380 6291456
net.ipv4.tcp_wmem = 4096 65536 4194304
net.ipv4.tcp_max_tw_buckets = 262144
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.core.somaxconn = 65535
重新加载下
sysctl -p
关闭selinux
vim /etc/selinux/config
SELINUX=disabled
setenforce 0
mysql安装
mysql 5.7编译cmake要求版本最低为2.8
升级cmake
yum -y install ncurses-devel cmake
创建用户和用户组
groupadd mysql
useradd -g mysql mysql
usermod -s /sbin/nologin mysql
创建目录
mkdir -p /data/3306/data /data/3306/logs
解压软件包
tar zxvf mysql-5.7.14.tar.gz -C /usr/src/
cd /usr/src/mysql-5.7.14/
注意boost_1_59_0.tar.gz的路径,这里我是放在/opt下的
编译
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/3306/data \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/data/3306/mysqld.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_SSL=bundled \
-DWITH_DEBUG=0 \
-DENABLE_DOWNLOADS=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/opt/boost_1_59_0.tar.gz
安装
make && make install
设置权限
chown mysql:mysql -R /data/3306 /usr/local/mysql
初始化
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data
以root初始化操作时要加–user=mysql参数,生成一个随机密码(注意保存登录时用)
2017-12-11T03:54:23.999606Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-11T03:54:24.644107Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-12-11T03:54:24.699612Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-12-11T03:54:24.818426Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: fa567738-de26-11e7-9c63-000c29e367e9.
2017-12-11T03:54:24.821586Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-12-11T03:54:24.825428Z 1 [Note] A temporary password is generated for root@localhost: K&Al1pUsfkl8
以上信息可以看到随机密码为 K&Al1pUsfkl8
备份配置文件
cd /etc/
mv my.cnf my.cnf.bak
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
编辑配置文件
vim my.cnf
basedir = /usr/local/mysql
datadir = /data/3306/data
port = 3306
server_id = 2
socket = /data/3306/mysqld.sock
pid-file = /data/3306/mysql.pid
max_allowed_packet=16M
log-error = /data/3306/logs/error.log
chown mysql:mysql -R /data/3306 /usr/local/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
编辑环境变量
vim /etc/profile
最后一行添加
PATH=$PATH:/usr/local/mysql/bin
重新加载环境变量,启动mysql
source /etc/profile
/etc/init.d/mysqld start
Starting MySQL. SUCCESS!
进入Mysql
mysql -u root -p
输入密码:K&Al1pUsfkl8
修改密码为root
alter user 'root'@'localhost' identified by '要更改的密码';
quit;
再次进入
mysql -u root -p
执行命令,就可以了
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
exit;
php-7.0.9安装
创建用户和组
groupadd www
useradd -g www www
usermod -s /sbin/nologin www
安装组件
yum install -y libxml2 libxml2-devel libxml2-python curl curl-devel libjpeg libjpeg-devel libpng libpng10 libpng10-devel libpng-devel freetype-devel libmcrypt libmcrypt-devel gd gd-devel
解压
tar zxvf php-7.0.9.tar.gz -C /usr/src/
cd /usr/src/php-7.0.9/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
--with-libxml-dir --enable-xml --enable-bcmath \
--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl \
--enable-mbregex --enable-fpm --enable-mbstring \
--with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash \
--enable-pcntl --enable-sockets \
--with-xmlrpc --enable-zip --enable-soap --with-mysqlsock=/data/3306/mysqld.sock \
--with-curl=/usr --with-gettext --with-iconv --enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
安装
make && make install
复制配置文件以及启动脚本
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cd /usr/local/php/etc/php-fpm.d
编辑配置文件
vim www.conf
修改用户和组为www
user = www
group = www
脚本设置权限,添加到开机自启动
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --level 2345 php-fpm on
启动php-fpm
/etc/init.d/php-fpm start
查看端口是否启动
netstat -anpt | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3208/php-fpm: maste
Tengine 安装
解压软件包,其中openssl,pcre,zlib都是最新版
tar zxvf openssl-1.0.1t.tar.gz -C /usr/src/
tar zxvf pcre-8.39.tar.gz -C /usr/src/
tar zxvf zlib-1.2.8.tar.gz -C /usr/src/
tar zxvf tengine-2.2.1.tar.gz -C /usr/src/
cd /usr/src/tengine-2.2.1/
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-openssl=/usr/src/openssl-1.0.1t --with-zlib=/usr/src/zlib-1.2.8 --with-pcre=/usr/src/pcre-8.39
make && make install
修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;
client_max_body_size 64M;
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;
fastcgi_intercept_errors on;
include vhosts/*;
}
cd /usr/local/nginx/conf/
mkdir vhosts
vim zabbix.conf
server {
listen 80;
server_name ip地址或者域名;
root /usr/local/zabbix/php;
index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
检查nginx配置
/usr/local/nginx/sbin/nginx -t
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
/usr/local/nginx/sbin/nginx
写入开机自动启动
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
nginx日志切割
mkdir -p /manage
cd /manage/
vim nginx_cut.sh
#!/bin/bash
source /etc/profile
#/usr/local/nginx/sbin/nginx -s stop
cd /usr/local/nginx/logs
mv access.log access_$(date -d "today" +"%Y%m%d").log
mv error.log error_$(date -d "today" +"%Y%m%d").log
/usr/local/nginx/sbin/nginx -s reload
#日志保留7天
find /usr/local/nginx/logs -mtime +7 -type f -name "*.log" -exec rm {} \;
chmod 755 nginx_cut.sh
添加任务计划
crontab -e
10 4 * * * /manage/nginx_cut.sh
netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23150/nginx: master
zabbix安装
创建zabbix用户
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
解压源码包
tar zxvf zabbix-3.4.4.tar.gz -C /usr/src/
进入数据库
mysql -u root -p
创建zabbix数据库
CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
创建zabbix授权库账户zabbix,密码是123456
grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
导入zabbix数据表结构
use zabbix;
source /usr/src/zabbix-3.4.4/database/mysql/schema.sql;
source /usr/src/zabbix-3.4.4/database/mysql/data.sql;
source /usr/src/zabbix-3.4.4/database/mysql/images.sql;
安装组件
yum install -y net-snmp net-snmp-devel curl curl-devel
进入解压目录,编译安装
cd /usr/src/zabbix-3.4.4/
./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy
编译过程中报错
configure: error: Unable to use libevent (libevent check failed)
解决方法
yum install libevent libevent-devel -y
重新编译
./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy
成功应该看到的结果
make && make install
创建日志目录
mkdir /usr/local/zabbix/logs
编辑zabbix_agentd配置文件
cd /usr/local/zabbix/etc/
mv zabbix_agentd.conf zabbix_agentd.conf.bak
vim zabbix_agentd.conf
内容如下:
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Server=127.0.0.1
#ServerActive=127.0.0.1
Hostname=Zabbix server
编辑zabbix_server配置文件
mv zabbix_server.conf zabbix_server.conf.bak
vim zabbix_server.conf
内容如下:
LogFile=/usr/local/zabbix/logs/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBHost=localhost
DBPassword=123456
AlertScriptsPath=/usr/local/zabbix/alertscripts
创建自定义脚本目录,设置权限,目录下的脚步,可以被zabbix调用
mkdir /usr/local/zabbix/alertscripts
chown zabbix:zabbix -R /usr/local/zabbix
更改php.ini文件
sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone =PRC/' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini
cgi.fix_pathinfo=0
改为
cgi.fix_pathinfo=1
重启php-fpm
service php-fpm restart
进入源码目录,复制启动脚本
cd /usr/src/zabbix-3.4.4/misc/
cp init.d/tru64/zabbix_server /etc/init.d/
cp init.d/tru64/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_*
修改zabbix_agentd、zabbix_server程序目录的位置
vim /etc/init.d/zabbix_agentd
内容如下:
DAEMON=/usr/local/zabbix/sbin/zabbix_agentd
vim /etc/init.d/zabbix_server
内容如下:
DAEMON=/usr/local/zabbix/sbin/zabbix_server
由于zabbix_server 服务不支持 chkconfig,使用下列方法自启动
vim /etc/init.d/zabbix_server
在#!/bin/sh下面一行添加
#chkconfig: 345 95 95
#description: Zabbix_Server
vim /etc/init.d/zabbix_agentd
在#!/bin/sh下面一行添加
#chkconfig: 345 95 95
#description: Zabbix_agentd
添加到系统服务
chkconfig zabbix_server on
chkconfig zabbix_agentd on
编辑系统库配置文件
vim /etc/ld.so.conf
加入一行
/usr/local/mysql/lib/
重新加载
ldconfig
启动服务
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
查看端口
netstat -ntpl|grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 21188/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 21140/zabbix_server
复制php页面,并设置权限
cp -rf /usr/src/zabbix-3.4.4/frontends/php/ /usr/local/zabbix/php
chown www:www -R /usr/local/zabbix/php/
重新加载nginx
/usr/local/nginx/sbin/nginx -s reload
编辑php配置文件,开启中文
vim /usr/local/zabbix/php/include/locales.inc.php
'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => true],
下载微软雅黑字体,放到/root目录
将zabbix默认的字体覆盖
cd /usr/local/zabbix/php/fonts/
\cp /opt/msyh.ttf DejaVuSans.ttf
访问zabbix安装页面
http://ip地址或者域名/setup.php
下一步
这里报错
解决方法
vim /usr/local/php/etc/php.ini
mysqli.default_socket = /data/3306/mysqld.sock
/usr/local/nginx/sbin/nginx -s reload
/etc/init.d/php-fpm restart
在刷新页面
后面的下一步安装即可
访问http://192.168.0.110
这里注意 zabbix默认页面
帐号:admin
密码:zabbix
进去后可修改
上一篇: LDAP认证服务器
下一篇: zabbix-agent(客户端安装)
47605
45985
36909
34469
29080
25713
24566
19714
19245
17756
5564°
6155°
5691°
5737°
6705°
5483°
5484°
5988°
5965°
7295°