目录
我叫张贺,贪财好色。一名合格的LINUX运维工程师,专注于LINUX的学习和研究,曾负责某中型企业的网站运维工作,爱好佛学和跑步。
个人网站:传送阵
笔者微信:zhanghe15069028807
,非诚勿扰。
zabbix-redis
discuz论坛的搭建和wordpress的搭建思路是相同的,我们搭建一个discuz论坛并不是目的,而是想通过discuz配合redis,然后用zabbix监控redis。
1、nginx
//统一用户www,提前创建
groupadd -g 666 www;
useradd -u 666 -g 666 -M -s /sbin/nologin www;
//用官方的yum源
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
//安装
yum -y install nginx
//更改主配置文件的启动用户
[root@nginx conf.d]# vim /etc/nginx/nginx.conf
user www;
//编写站点文件
[root@nginx conf.d]# vim default.conf
server {
listen 80;
server_name localhost;
location / {
root /code;
index index.php;
}
location ~ \.php$ {
root /code;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
//创建站点目录
mkdir /code
//上传discuz包,unzip解压到/code目录
wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_UTF8.zip
[root@nginx code]# mv discuz/* ./
//更改权限
[root@nginx code]# chown -R www:www /code
//启动
systemctl start nginx
systemctl enable nginx
//检查
ss -tnlp | grep 80
ps aux | grep nginx
2、mariadb
//安装启动,设置密码
yum -y install mariadb-server mariadb
systemctl start mariadb
mysql_secure_installation #初始化并设置密码
//创建wordpress数据库
create database discuz;
//创建wordpress用户对wordpress数据库的授权
grant ALL on discuz.* to discuz@'localhost' identified by 'cba-123';
3、php7.3
yum -y install epel-release
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xml
//统一用户
rpm -ql php73-php-fpm | grep conf
/etc/opt/remi/php73/php-fpm.d/www.conf
vim /etc/opt/remi/php73/php-fpm.d/www.conf
user = www
group = www
//启动
systemctl enable php73-php-fpm
systemctl start php73-php-fpm
4、redis
//安装redis
yum -y install redis
//安装php和redis联动的模块,注意版本
yum list | grep php|grep redis
yum -y install php73-php-pecl-redis4.x86_64
//重启php
systemctl restart php73-php-fpm
//给reids设置一个密码,跨主机的话还要更改bind参数,这里不用更改
vim /etc/redis.conf
requirepass cba-123
systemctl restart redis
ss -tnlp | grep 6379 #redis监听到6379
//修改discuz的配置文件,让discuz连接redis
vim /code/config/config_global.php
$_config['memory']['redis']['server'] = '127.0.0.1';
$_config['memory']['redis']['requirepass'] = 'cba-123';
5、界面
后面就是在浏览器*问,在界面上连接数据库。
管理员登录---全局--性能优化--内存优化--redis可以看到redis的支持关键字:
6、zabbix-redis
ls
redis.conf
redis.sh
redis.xml
//修改脚本,加上redis的密码
vim redis.sh
redis-cli -a cba-123 -h $SERV -p $PORT info > $CACHE
//将配置文件copy到agent的目录下
cp redis.conf /etc/zabbix/zabbix_agentd.d/
cat /etc/zabbix/zabbix_agentd.d/redis.conf
UserParameter=redis.discovery,/etc/zabbix/scripts/redis.sh localhost list_key_space_db
UserParameter=redis[*],/etc/zabbix/scripts/redis.sh $1 $2 $3
//根据配置文件将脚本放入正确的位置
mkdir /etc/zabbix/scripts/
cp redis.sh /etc/zabbix/scripts/
//先将模板导入到zabbix-server,修改间隔时间20s,修改宏:127.0.0.1
如果出现/tmp/某个文件权限拒绝,就删除/tmp里面那个文件即可
完美的监控到了redis的所有值