一、下载nginx
http://nginx.org/download/nginx-1.12.1.tar.gz
二、下载MySQL
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz
三、下载php
http://hk1.php.net/get/php-7.1.8.tar.gz/from/this/mirror
四、下载cmake(MySQL编译工具)
https://cmake.org/files/v3.9/cmake-3.9.1.tar.gz
五、下载pcre (支持nginx伪静态)
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
六、下载openssl(nginx扩展)
https://www.openssl.org/source/openssl-1.1.0f.tar.gz
七、下载zlib(nginx扩展)
http://www.zlib.net/zlib-1.2.11.tar.gz
八、下载libmcrypt(php扩展)
https://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
九、下载yasm(php扩展)
http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
十、t1lib(php扩展)
http://download.freenas.org/distfiles/t1lib-5.1.2.tar.gz
十一、下载gd库安装包
https://github.com/libgd/libgd/releases/download/gd-2.2.4/libgd-2.2.4.tar.gz
十二、libvpx(gd库须要)
http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.1.tar.bz2
1三、tiff(gd库须要)
http://download.osgeo.org/libtiff/tiff-4.0.8.tar.gz
1四、libpng(gd库须要)
https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.32/libpng-1.6.32.tar.gz
1五、freetype(gd库须要)
http://ftp.yzu.edu.tw/nongnu/freetype/freetype-2.8.tar.gz
1六、jpegsrc(gd库须要)
http://www.ijg.org/files/jpegsrc.v9b.tar.gz、
1七、Boost(编译mysql须要)
https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
以上软件包上传到/usr/local/src目录php
yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* \ cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel \ gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers \ keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel \ libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp \ libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* \ make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common \ php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel \
cd /usr/local/src tar zxvf cmake-3.9.1.tar.gz cd cmake-3.9.1 ./configure make make install
cd /usr/local/src mkdir -p /usr/local/boost cp boost_1_65_0.tar.gz /usr/local/boost useradd -s /sbin/nologin mysql #建立用户mysql,不容许mysql用户直接登陆系统 mkdir -p /data/mysql #建立MySQL数据库存放目录 chown -R mysql:mysql /data/mysql #设置MySQL数据库存放目录权限 mkdir -p /usr/local/mysql #建立MySQL安装目录 cd /usr/local/src #进入软件包存放目录 tar xf mysql-5.7.19.tar.gz #解压 cd mysql-5.7.19 #进入目录 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EMBEDDED_SERVER=OFF \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/usr/local/boost \ -DSYSCONFDIR=/etc \
注意:可使用 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost 参数在线安装boost软件包,须要服务器联网,容易下载失败。html
编译出错, 从新编译前要删除编译失败的文件,从新编译时,须要清除旧的对象文件和缓存信息。mysql
make clean rm -f CMakeCache.txt
make #编译 make install #安装
rm -rf /etc/my.cnf #删除系统默认的配置文件(若是默认没有就不用删除) ps aux|grep mysql|grep 'my.cnf' #查看使用的配置文件 mysql --help|grep 'my.cnf' # 读取配置文件路径 cd /usr/local/mysql #进入MySQL安装目录 ./bin/mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系统数据库 --initialize表示默认生成密码, --initialize-insecure 表示不生成密码, 密码为空。 看到这一行[Note] A temporary password is generated for root@localhost: i>X18*=Rav=7 ln -s /usr/local/mysql/my.cnf /etc/my.cnf #添加到/etc目录的软链接 cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动 chmod 755 /etc/init.d/mysqld #增长执行权限 chkconfig mysqld on #加入开机启动 vim /etc/rc.d/init.d/mysqld #编辑 basedir=/usr/local/mysql #MySQL程序安装路径 datadir=/data/mysql #MySQl数据库存放目录 vim /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行 export PATH=$PATH:/usr/local/mysql/bin 下面这两行把myslq的库文件连接到系统默认的位置,这样你在编译相似PHP等软件时能够不用指定mysql的库文件地址。 ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql ln -s /usr/local/mysql/include/mysql /usr/include/mysql mkdir /var/lib/mysql #建立目录 ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软连接 mysql_secure_installation #修改Mysql密码,输入以前生成的密CSJlm3DyTG.d回车,根据提示操做 Press y|Y for Yes, any other key for No: y #是否安装密码安全插件?选择y There are three levels of password validation policy: #有如下几种密码强度选择 LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 #选择0,只要8位数字便可,选1要有大写,小写,特殊字符等 UNINSTALL PLUGIN validate_password ; #卸载密码强度插件 use mysql; update mysql.user set authentication_string=password('123456') where user='root' ; #登陆mysql控制台修改
cd /usr/local/src mkdir /usr/local/pcre tar zxvf pcre-8.41.tar.gz cd pcre-8.41 ./configure --prefix=/usr/local/pcre make make install
cd /usr/local/src mkdir /usr/local/openssl tar zxvf openssl-1.1.0f.tar.gz cd openssl-1.1.0f ./config --prefix=/usr/local/openssl make make install vim /etc/profile export PATH=$PATH:/usr/local/openssl/bin source /etc/profile
cd /usr/local/src tar zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure --prefix=/usr/local/zlib make make install
useradd -s /sbin/nologin www cd /usr/local/src tar zxvf nginx-1.12.1.tar.gz cd nginx-1.12.1 ./configure --prefix=/usr/local/nginx \ --without-http_memcached_module \ --user=www \ --group=www \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-http_gzip_static_module \ --with-openssl=/usr/local/src/openssl-1.1.0f \ --with-zlib=/usr/local/src/zlib-1.2.11 \ --with-pcre=/usr/local/src/pcre-8.41 \ 注意:--with-openssl=/usr/local/src/openssl-1.1.0f --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.41 指向的是源码包解压的路径,而不是安装的路径,不然会报错 make make install 配置NGINX systemd service (注意:根据本身配置,配置路径信息!) vim /usr/lib/systemd/system/nginx.service [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx restart ExecStop=/usr/local/nginx/sbin/nginx stop PrivateTmp=true [Install] WantedBy=multi-user.target 编译安装的nginx不会作日志分割 vim logrotate.sh #!/bin/bash cd /var/log/nginx mv access.log access.log.$(date +%F) mv error.log error.log.$(date +%F) kill -USR1 $(cat /var/log/nginx/run/nginx.pid) sleep 1 gzip access.log.$(date +%F) gzip error.log.$(date +%F) 经过crontab实现定时日志轮替。
cd /usr/local/src tar zxvf yasm-1.3.0.tar.gz cd yasm-1.3.0 ./configure make make install
cd /usr/local/src tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make make install
cd /usr/local/src tar zxvf libvpx-1.6.1.tar.bz2 cd libvpx-1.6.1 ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9 make make install
cd /usr/local/src tar zxvf tiff-4.0.8.tar.gz cd tiff-4.0.8 ./configure --prefix=/usr/local/tiff --enable-shared make make install
cd /usr/local/src tar zxvf libpng-1.6.32.tar.gz cd libpng-1.6.32 ./configure --prefix=/usr/local/libpng --enable-shared make make install
cd /usr/local/src tar zxvf freetype-2.8.tar.gz cd freetype-2.8 ./configure --prefix=/usr/local/freetype --enable-shared make make install
cd /usr/local/src tar zxvf jpegsrc.v9b.tar.gz cd jpeg-9b ./configure --prefix=/usr/local/jpeg --enable-shared make make install
cd /usr/local/src tar zxvf libgd-2.2.4.tar.gz cd libgd-2.2.4 ./configure --prefix=/usr/local/libgd \ --enable-shared \ --with-jpeg=/usr/local/jpeg \ --with-png=/usr/local/libpng \ --with-freetype=/usr/local/freetype \ --with-fontconfig=/usr/local/freetype \ --with-xpm=/usr/lib64 \ --with-tiff=/usr/local/tiff \ make make install 说明:若是libgd编译失败,能够先跳过,直接使用系统默认的2.1.0版本,在编译php的时候把参数--with-gd=/usr/local/libgd修改成--with-gd便可。
cd /usr/local/src tar zxvf t1lib-5.1.2.tar.gz cd t1lib-5.1.2 ./configure --prefix=/usr/local/t1lib --enable-shared make without_doc make install
注意:若是系统是64位,请执行如下两条命令,不然安装php会出错。linux
cp -frp /usr/lib64/libltdl.so* /usr/lib/ cp -frp /usr/lib64/libXpm.so* /usr/lib/
cd /usr/local/src tar -zvxf php-7.1.8.tar.gz cd php-7.1.8 export LD_LIBRARY_PATH=/usr/local/libgd/lib ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --with-mysql-sock=/tmp/mysql.sock \ --with-pdo-mysql=/usr/local/mysql \ --with-gd=/usr/local/libgd \ --with-png-dir=/usr/local/libpng \ --with-jpeg-dir=/usr/local/jpeg \ --with-freetype-dir=/usr/local/freetype \ --with-xpm-dir=/usr/lib64 \ --with-zlib-dir=/usr/local/zlib \ --with-iconv \ --enable-libxml \ --enable-xml \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --enable-opcache \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --enable-ftp \ --enable-gd-native-ttf \ --with-openssl \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --without-pear \ --with-gettext \ --enable-session \ --with-mcrypt \ --with-curl \ --enable-ctype \ --enable-mysqlnd \ make #编译 make install #安装 说明:若是提示libgd版本错误,把php编译参数--with-gd=/usr/local/libgd修改成--with-gd便可。
配置文件nginx
cp php.ini-production /usr/local/php/etc/php.ini #复制php配置文件到安装目录 rm -rf /etc/php.ini #删除系统自带配置文件 ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加软连接到 /etc目录
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件 ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #添加软链接到 /etc目录 vim /usr/local/php/etc/php-fpm.conf #编辑 pid = run/php-fpm.pid #取消前面的分号
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf vim /usr/local/php/etc/php-fpm.d/www.conf #编辑 user = www #设置php-fpm运行帐号为www group = www #设置php-fpm运行组为www
设置 php-fpm开机启动c++
vim /usr/lib/systemd/system/php-fpm.service [Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target
vim /usr/local/php/etc/php.ini #编辑配置文件 找到:disable_functions = 修改成:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open, proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink, symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space, checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid, posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid, posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times, posix_ttyname,posix_uname #列出PHP能够禁用的函数,若是某些程序须要用到这个函数,能够删除,取消禁用。
找到:;date.timezone = 修改成:date.timezone = PRC #设置时区 找到:expose_php = On 修改成:expose_php = Off #禁止显示php版本的信息 找到:short_open_tag = Off 修改成:short_open_tag = ON #支持php短标签 找到opcache.enable=0 修改成opcache.enable=1 #php支持opcode缓存 找到:;opcache.enable_cli=1 #php支持opcode缓存 修改成:opcache.enable_cli=0 在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能
配置nginx支持phpgit
vim /usr/local/nginx/conf/nginx.conf 修改/usr/local/nginx/conf/nginx.conf 配置文件,需作以下修改 user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,不然php运行出错 index index.html index.htm index.php; #添加index.php # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改成$document_root$fastcgi_script_name,或者使用绝对路径
systemctl restart nginx systemctl restart php-fpm
测试github
chmod 700 /usr/local/nginx/html/ -R #设置目录权限 cd /usr/local/nginx/html/ #进入nginx默认网站根目录 rm -rf /usr/local/nginx/html/* #删除默认测试页 vim index.php #新建index.php文件 <?php phpinfo(); ?> chown www.www /usr/local/nginx/html/ -R #设置目录全部者
cd /usr/local/src #进入软件包下载目录 tar zabbix-3.0.1.tar.gz #解压 cd /usr/local/src/zabbix-3.0.1/database/mysql #进入mysql数据库建立脚本目录 ls #列出文件,能够看到有schema.sql、images.sql、data.sql这三个文件 mysql -u root -p #输入密码,进入MySQL控制台 create database zabbix character set utf8; #建立数据库zabbix,而且数据库编码使用utf8 grant all on zabbix.* to 'zabbix'@'localhost' identified by '123456' with grant option; #容许帐户zabbix能从本机链接到数据库zabbix flush privileges; #刷新系统受权表 # zabbix进入mysql use zabbix #进入数据库 source /usr/local/src/zabbix-3.4.1/database/mysql/schema.sql; #导入脚本文件到zabbix数据库 source /usr/local/src/zabbix-3.4.1/database/mysql/images.sql; #导入脚本文件到zabbix数据库 source /usr/local/src/zabbix-3.4.1/database/mysql/data.sql; #导入脚本文件到zabbix数据库 注意:请按照以上顺序进行导入,不然会出错。
cd /usr/lib64/mysql #32位系统为/usr/lib/mysql,注意系统版本同,文件版本可能不同,这里是16.0.0 ln -s libmysqlclient.so.16.0.0 libmysqlclient.so #添加软链接 ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so #添加软链接
useradd -s /sbin/nologin zabbix #建立用户zabbix
yum install net-snmp-devel curl curl-devel mysql-devel
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2 #添加软链接 /sbin/ldconfig #使配置当即生效 cd /usr/local/src/zabbix-3.4.1 #进入安装目录 ./configure --prefix=/usr/local/zabbix \ --enable-server \ --enable-agent \ --with-mysql \ --enable-ipv6 \ --with-net-snmp \ --with-libcurl \ --with-libxml2 \ make #编译 make install #安装
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ #添加系统软链接 ln -s /usr/local/zabbix/bin/* /usr/local/bin/ #添加系统软链接
vim /etc/services #编辑,在最后添加如下代码 # Zabbix zabbix-agent 10050/tcp # Zabbix Agent zabbix-agent 10050/udp # Zabbix Agent zabbix-trapper 10051/tcp # Zabbix Trapper zabbix-trapper 10051/udp # Zabbix Trapper
cd /usr/local/zabbix/etc vim /usr/local/zabbix/etc/zabbix_server.conf DBName=zabbix #数据库名称 DBUser=zabbix #数据库用户名 DBPassword=123456 #数据库密码 ListenIP=localhost #数据库ip地址 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix运行脚本存放目录 vim /usr/local/zabbix/etc/zabbix_agentd.conf Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ UnsafeUserParameters=1 #启用自定义key
cp /usr/local/src/zabbix-3.4.1/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server #服务端 cp /usr/local/src/zabbix-3.4.1/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd #客户端 chkconfig zabbix_server on #添加开机启动 chkconfig zabbix_agentd on #添加开机启动
vim /etc/rc.d/init.d/zabbix_server #编辑服务端配置文件 BASEDIR=/usr/local/zabbix/ #zabbix安装目录 vim /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件 BASEDIR=/usr/local/zabbix/ #zabbix安装目录
cd /usr/local/src/zabbix-3.4.1 cp -r /usr/local/src/zabbix-3.4.1/frontends/php /usr/local/nginx/html/zabbix chown www.www -R /usr/local/nginx/html/zabbix 备注:/usr/local/nginx/html为Nginx默认站点目录 www为Nginx运行帐户 service zabbix_server start #启动zabbix服务端 service zabbix_agentd start #启动zabbix客户端
一、vim /etc/php.ini #编辑修改web
post_max_size =16M max_execution_time =300 max_input_time =300
二、vim /usr/local/php/etc/php-fpm.conf #编辑修改sql
request_terminate_timeout = 300
一、修改系统配置文件,让web页面支持简体中文显示 vim /usr/local/nginx/html/zabbix/include/locales.inc.php #编辑修改 'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => false), 修改成 'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => true),
替换监控图像上系统默认的字体 #默认字体不支持中文,若是不替换,图像上会显示乱码 usr/local/nginx/html/zabbix/fonts 备份默认的字体文件:DejaVusSans.ttf-bak 修改msyh.ttf名称为DejaVusSans.ttf