詹学伟

詹学伟

一个爱好编程的90后站长。

关注我詹学伟个人微信号:tobecomputer

您现在的位置是:网站首页>专业交流

  • Android解析带网络图片的富文本

    Android解析带网络图片的富文本

    android解析带网络图片的富文本这个问题弄了有很一会儿,原本我以为android会有像小程序一样的好用的richtext工具,可惜没有找到。终于不负苦心人,直接上代码:import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.drawable.BitmapDrawable;import android.graphics.drawable.Drawable;import android.graphics.drawable.LevelListDrawable;import android.os.AsyncTask;import android.text.Html;import android.util.Log;import android.widget.TextView;import com.wekair.app.R;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.net.MalformedURLException;import java.net.URL;import java.security.KeyManagementException;import java.security.NoSuchAlgorithmException;import java.security.SecureRandom;import java.security.cert.X509Certificate;import javax.net.ssl.HostnameVerifier;import javax.net.ssl.HttpsURLConnection;import javax.net.ssl.SSLContext;import javax.net.ssl.SSLSession;import javax.net.ssl.TrustManager;import javax.net.ssl.X509TrustManager;public class HtmlImageGetter implements Html.ImageGetter{ private Context context; private final int widthPixels; private TextView textView; public HtmlImageGetter(Context context, TextView textView){ this.context = context; this.textView = textView; widthPixels = context.getResources().getDisplayMetrics().widthPixels; } /** * 获取图片 */ @Override public Drawable getDrawable(String source) { LevelListDrawable d = new LevelListDrawable(); Drawable empty = context.getResources().getDrawable( R.mipmap.img_default); d.addLevel(0, 0, empty); d.setBounds(0, 0,widthPixels, empty.getIntrinsicHeight()); new LoadImage().execute(source, d); return d; } /** * 异步下载图片类 * * */ class LoadImage extends AsyncTask<Object, Void, Bitmap> { private LevelListDrawable mDrawable; @Override protected Bitmap doInBackground(Object... params) { String source = (String) params[0]; mDrawable = (LevelListDrawable) params[1]; //特殊处理,进行来处理https协议进行来显示的图片 X509TrustManager xtm = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) { } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) { } @Override public X509Certificate[] getAcceptedIssuers() { X509Certificate[] x509Certificates = new X509Certificate[0]; return x509Certificates; } }; SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, new TrustManager[]{xtm}, new SecureRandom()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }; try { URL url = new URL(source); HttpsURLConnection httpsURLConnection= (HttpsURLConnection) url.openConnection(); httpsURLConnection.setHostnameVerifier(DO_NOT_VERIFY); httpsURLConnection.setSSLSocketFactory(sslContext.getSocketFactory()); InputStream is = httpsURLConnection.getInputStream(); return BitmapFactory.decodeStream(is); } catch (Exception e) { e.printStackTrace(); } return null; } /** * 图片下载完成后执行 */ @Override protected void onPostExecute(Bitmap bitmap) { if (bitmap != null) { try{ BitmapDrawable d = new BitmapDrawable(bitmap); mDrawable.addLevel(1, 1, d); /** * 适配图片大小 <br/> * 默认大小:bitmap.getWidth(), bitmap.getHeight()<br/> * 适配屏幕:getDrawableAdapter */ mDrawable = getDrawableAdapter(context, mDrawable, bitmap.getWidth(), bitmap.getHeight()); // mDrawable.setBounds(0, 0, bitmap.getWidth(), // bitmap.getHeight()); mDrawable.setLevel(1); /** * 图片下载完成之后重新赋值textView<br/> * mtvActNewsContent:我项目中使用的textView * */ textView.invalidate(); CharSequence t = textView.getText(); textView.setText(t); }catch (Exception e){ Log.e("onPostExecute", "onPostExecute: "+e.toString() ); } } } /** * 加载网络图片,适配大小 * */ public LevelListDrawable getDrawableAdapter(Context context, LevelListDrawable drawable, int oldWidth, int oldHeight) { LevelListDrawable newDrawable = drawable; long newHeight = 0;// 未知数 newHeight = (widthPixels * oldHeight) / oldWidth; // LogUtils.w("oldWidth:" + oldWidth + "oldHeight:" + // oldHeight); // LogUtils.w("newHeight:" + newHeight + "newWidth:" + // newWidth); newDrawable.setBounds(0, 0, widthPixels, (int) newHeight); return newDrawable; } }}使用方法:courseIntroduction.setText(Html.fromHtml(s,new HtmlImageGetter(mContext,courseIntroduction), null));说明:courseIntroduction :textView对象s:原文本后面的两个参数就不用解释了 。另外,再上一个遇到的问题 :HttpURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection解决:之所以会出现那样的异常就在于下面这段代码的错误URL url = new URL(urlString);HttpsURLConnection connection= (HttpsURLConnection) url.openConnection();我请求的图片的网址 开头是Http://,而却用 HttpsURLConnection类型来指定网络连接的类型,肯定会抛出异常。。。问题原因:你的urlString必须以这种形式开头:“http://” 而不是“https://” 这样你才能匹配HttpURLConnection.解决办法:将HttpsURLConnection改为HttpURLConnection即可;本文参考:https://blog.csdn.net/liu_jing_hui/article/details/78797407

    2020-12-08 詹学伟 专业交流 53 0

  • Android之CheckBox的两种处理改变状态的方法

    Android之CheckBox的两种处理改变状态的方法

    Android之CheckBox的两种处理改变状态的方法一、使用监听器页面: <?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <CheckBox android:id="@+id/checkbox_meat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="52dp" android:layout_marginLeft="52dp" android:layout_marginTop="104dp" android:checked="true" android:text="checkbox_meat" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:ignore="MissingConstraints" /> <CheckBox android:id="@+id/checkbox_cheese" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="160dp" android:layout_marginLeft="160dp" android:layout_marginTop="104dp" android:checked="true" android:text="checkbox_cheese" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:ignore="MissingConstraints" /></androidx.constraintlayout.widget.ConstraintLayout>代码:package com.example.loginappdemo;import android.os.Bundle;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); CheckBox meatBox = (CheckBox) findViewById(R.id.checkbox_meat); CheckBox cheeseBox = (CheckBox) findViewById(R.id.checkbox_cheese); CheckListener listener = new CheckListener();//声明实例化 监听器对象 meatBox.setOnCheckedChangeListener(listener);//设置setOn监听器CheckedChangeListener,参数是监听器对象 cheeseBox.setOnCheckedChangeListener(listener);//不论哪个控件被点击,都会调用onCheckedChanged()方法 } private class CheckListener implements CompoundButton.OnCheckedChangeListener { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { System.out.println("aaa"); String format = String.format("you checked %d ,status is %b", buttonView.getId(), buttonView.isChecked()); Toast.makeText(MainActivity.this, format, Toast.LENGTH_LONG).show(); } }}说明:使用了CompoundButton.OnCheckedChangeListener监听器注意看CompoundButton:具有两个状态的按钮,已选中或未选中。当按下或点击按钮时,状态会自动更改。直接继承至Button直接子类CheckBoxRadioButtonSwitchSwitchCompatToggleButton间接子类AppCompatCheckBoxAppCompatRadioButton 二、使用onClick()方法触发<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <CheckBox android:id="@+id/checkbox_meat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="52dp" android:layout_marginLeft="52dp" android:layout_marginTop="104dp" android:checked="true" android:onClick="onCheckboxClicked" android:text="111" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:ignore="MissingConstraints" /> <CheckBox android:id="@+id/checkbox_cheese" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="160dp" android:layout_marginLeft="160dp" android:layout_marginTop="104dp" android:checked="true" android:onClick="onCheckboxClicked" android:text="111" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:ignore="MissingConstraints" /></androidx.constraintlayout.widget.ConstraintLayout> 页面代码和之前几乎一样,唯一不同是添加了android:onClick="onCheckboxClicked" 代码:public void onCheckboxClicked(View view) { // Is the view now checked? boolean checked = ((CheckBox) view).isChecked(); // Check which checkbox was clicked switch (view.getId()) { case R.id.checkbox_meat: if (checked) { System.out.println("1111111"); break; } else { System.out.println("222222"); break; } case R.id.checkbox_cheese: if (checked) { System.out.println("33333"); break; } else { System.out.println("44444"); // I'm lactose intolerant break; } default: break; }} 在MainActivity中添加一个方法,方法名和页面定义的一样。这个很好理解,相当于html和js一样。随后上一张效果图: 

    2020-12-02 zw 专业交流 34 0

  • springboot项目问题:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0

    springboot项目问题:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0

    问题:springboot项目build出错:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0解决方法写在前面:修改maven-resources-plugin的版本 <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- 在这里修改版本 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4.3</version> </plugin> </plugins> </build> 

    2020-11-24 zhanxuewei 专业交流 32 0

  • JDK10新特性一

    JDK10新特性一

     一、JDK10新特性1 局部变量类型推断var:保留类型。不是关键字/** * JDK10新特性:局部变量类型推断 * @author Administrator * */class Users{    private String username;    private Integer userage;    public String getUsername() {        return username;    }    public void setUsername(String username) {        this.username = username;    }     public Integer getUserage() {        return userage;    }     public void setUserage(Integer userage) {        this.userage = userage;    }    @Override    public String toString() {        return "Users [username=" + username + ", userage=" + userage + "]";    }} public class Demo1 {    /**     * 该特定注意点:     * 1.只针对局部变量     * 2.var 是保留类型不是关键字。意味着我们还可以用var来定义变量名或者是方法名     * 3.var 不允许赋值null     * @param args     */    public static void main(String[] args) {     var i = 10;     var str="abc";     var list = new ArrayList<>();     list.add("list test var");     var set = new HashSet<>();     set.add("set test var");     var map = new HashMap<String,String>();     map.put("test", "map test var");     var users = new Users();     users.setUserage(20);     users.setUsername("user test var");     System.out.println(i);     System.out.println(str);     for(var i1=0;i1<list.size();i1++) {         System.out.println(list.get(i1));     }     for(var temp :set) {         System.out.println(temp);     }     Set<String> keys = map.keySet();     for(var key :keys) {         System.out.println(map.get(key));     }     System.out.println(users);    }} 2  垃圾收集器的优化JDK9:新生代:ParNew收集器。老年代:Parallel Old收集器Stop The WorldJDK10:G1(Garbage-Frist)全收集器 二、新增73个新功能扩展API类库1         copyOf方法在java.util.List、java.util.Set、java.util.Map新增加了一个静态方法copyOf这些方法按照其迭代顺序返回一个不可修改的列表、集合或映射包含了给定的元素的集合。代码/** * copyOf方法的使用 * @author Administrator * */public class Demo2 {  public static void main(String[] args) {     var list = new ArrayList<String>();     list.add("a");     list.add("b");     list.add("c");     list.add("d");     var list2 = List.copyOf(list);     /*for (String string : list2) {        System.out.println(string);     }*/     var set = new HashSet<String>();     set.add("b");     set.add("a");     set.add("c");     set.add("d");     var set2 = Set.copyOf(set);     /*for (String string : set2) {        System.out.println(string);     }*/     var map = new HashMap<>();     map.put("k1", "a");     map.put("k2", "b");     var map2 = Map.copyOf(map);     var keys = map2.keySet();     for (Object object : keys) {        System.out.println(map2.get(object));     }  }}2 Java.io.ByteArrayOutputStream:toString(Charset)重载toString()方法,通过使用指定的字符集编码字节,将缓冲区的内容转换为字符串。代码/** * java.io.ByteArrayOutputStream.toString(Charset) * @author Administrator * */public class Demo3 {  public static void main(String[] args) throws Exception {     String str = "我是中国人";     ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes("gbk"));     ByteArrayOutputStream bos = new ByteArrayOutputStream();     int c = 0;     while((c = bis.read()) != -1) {        bos.write(c);     }     //bos.toString() 默认的使用的UTF-8编码     System.out.println(bos.toString());     System.out.println(bos.toString("gbk"));  }} 3 Java.io.PrintStream、java.io.PrintWriter这两个类都有三个新的构造方法,他们需要而外的参数charset代码/** * java.io.PrintStream、java.io.PrintlWriter新增构造方法 * @author Administrator * */public class Demo4 {  public static void main(String[] args) throws Exception{     String str = "中是中国人";     var p = new PrintWriter("d:/aa.txt", "gbk");     p.println(str);     p.flush();     p.close();  }}4  Java.io.Reader:transferTo方法从这个Reader中读取所有字符串,并按照所读取的顺序将字符串写入给指定的Writer/** * Reader:transferTo方法 * @author Administrator * */public class Demo5 {  public static void main(String[] args) throws Exception{     var reader = new BufferedReader(new InputStreamReader(new FileInputStream("d:/aa.txt"), "gbk"));     var p = new PrintWriter(new File("d:/cc.txt"));     reader.transferTo(p);     p.flush();     p.close();     reader.close();  }}5  java.util.Formatter、java.util.Scanner新增三个构造方法,除了其他参数之外,都需要一个charset参数/** * java.util.Scanner * @author Administrator * */public class Demo6 {  public static void main(String[] args) throws Exception {     var scan = new Scanner(new FileInputStream(new File("d:/aa.txt")),"gbk");     scan.useDelimiter(" |,");     while(scan.hasNext()) {        System.out.println(scan.next());     }  }}

    2020-11-21 zhanxuewei 专业交流 50 0

  • vim: error while loading shared libraries: /lib64/libgpm.so.2: file too short

    vim: error while loading shared libraries: /lib64/libgpm.so.2: file too short

    问题:vim: error while loading shared libraries: /lib64/libgpm.so.2: file too short 解决方式:yum provides *libgpm.so.2yum reinstall -y gpm-libs yum reinstall -y perl-libs yum update yum makecacheyum remove -y vim*yum install -y vim*

    2020-10-28 zhanxuewei 专业交流 64 0

  • marquee标签

    marquee标签

    html用marquee标签来实现文字滚动属性bai,常见参数如下:1.滚动方du向zhidirection(包括4个值:up、 down、 left和 right)语法:<marquee direction="滚动方向">...</marquee>2.滚动方式behavior(scroll:循环滚动,默认效果; slide:只滚动一次就停止; alternate:来回交替进行滚动)语法:<marquee behavior="滚动方式">...</marquee>3.滚动速度scrollamount(滚动速度是设置每次滚动时移动的长度,以像素为单位)语法:<marquee scrollamount="5">...</marquee>4.滚动延迟scrolldelay(设置滚动的时间间隔,单位是毫秒)语法:<marquee scrolldelay="100">...</marquee>5.滚动循环loop(默认值是-1,滚动会不断的循环下去)语法:<marquee loop="2">...</marquee>

    2020-10-25 詹学伟 专业交流 70 0

  • Idea Hadoop本地测试

    Idea Hadoop本地测试

    1.新建springboot项目,略 2.添加相关依赖<dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-jobclient</artifactId> <version>2.7.2</version> </dependency> 3.编写案例代码,如wordcount,代码略4.将hadoop集群的配置文件core-site.xml、hdfs-site.xml复制到项目resource目录下5.测试说明:测试方法: wordcount通常需要指定两个参数,一个为输入参数,即读取的文件,第二个为输出的目录,即计算后的结果存放的位置如上图:第一个参数/input:读取根目录下input文件,输出结果到/output下6.这样是不够的,还需要在本down下hadoop(和你搭建的集群版本一致)源码,并配置HADOOP_HOME环境变量说明:有的人在配置了环境变量后,运行的时候还是会报错,这个时候可以在代码中加入System.setProperty("hadoop.home.dir", "D:\\hadoop-2.7.2");   后面参数为你本地hadoop的环境变量路径,如:    7.需要将down下来的源码包中share/hadoop目录下所有的jar导入到idea  8.还需要一个关键的winutils.exe 和 hadoop.dll,将这两个文件放入到down下来的hadoop的bin目录winutils.exe 和 hadoop.dll文件网上可以找到,版本要一致。顺便讲一下,我是下载winutils包解压后的文件全部复制到hadoop的bin下了  最后测试:   

    2020-10-09 詹学伟 专业交流 96 0

  • linux ntp多台主机时间同步

    linux ntp多台主机时间同步

    通俗的讲,多台主机ntp时间同步,就是自定义集群中一台机器(我们这里叫它server)与网络时间同步,然后其它主机与server主机时间同步另外,ntp时间同步机制不是我们想象的那样直接同步,而是“逐渐”同步。这样的好处是,在某些情况下,比如两台主机时间不同步,而且两台主机上面都有定时任务,如果其中有一台是正常的,另外一台机器时间“快”一些,而在“快”的这段时间里,可能会已经触发某些定时任务,当时间同步后,这就意味着,这些定时任务将会再次被执行,这样肯定是不妥的。因此,npt同步机制通过“逐渐”同步的方法解决了这个问题。npt时间同步只需修改一下对应主机的配置文件:比如两台主机node1  192.168.100.101node2  192.168.100102  首先安装nptyum -y install npt 在server主机上修改配置文件配置,只需添加一行,其它都不用修改配置文件的位置:/etc/ntp.confvim /etc/ntp.confrestrict 192.168.0.0 mask 255.255.255.0   #添加此行 在其它主机上同步的配置修改,注释几行,然后添加一行vim /etc/ntp.confserver 192.168.100.102  然后在server和其它主机上重启ntp服务:systemctl start ntpd      没有启动的时候就直接启动   systemctl restart ntpd   已经启动就重以 centos6.x 上面命令不一样:service ntpd startservice ntpd restart 然后在各个主机上可以查看同步情况:ntpstat 大约15分分钟后就能好了

    2020-10-09 詹学伟 专业交流 81 0

  • yum 缓存包到本地

    yum 缓存包到本地

    yum install –downloadonly –downloaddir=/root/mypackages/ vim说明:--downloadonly  只下载--downloaddir  下载包存放的路径/root/mypackages  下载包存放的位置vim  下载的包rpm -ivh ./*.rpm --nodeps --force说明:安装所有包,因为通过第一个命令下载后有很多rpm包,他们之前有依赖关系,一个一个安装不实际

    2020-10-09 詹学伟 专业交流 60 0

  • zabbix离线安装

    zabbix离线安装

    LAMP环境1.apache安装#安装包(yum install --downloadonly --downloaddir=/opt/apache httpd httpd-devel)   1.1拷贝安装包到本地 1.2进入到安装包目录[root@node12 apache]# cd /opt/apache/ 1.3执行安装[root@node12 apache]# rpm -ivh ./*.rpm --nodeps --force 1.4启动服务systemctl start  httpd 1.5开启自启systemctl enable  httpd 1.6关闭防火墙systemctl stop firewalld 1.7浏览器测试结果   2.安装mysql数据库【安装包来源】wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpmrpm -ivh mysql-community-release-el7-5.noarch.rpmyum install --downloadonly --downloaddir=/opt/mysql mysql-server安装包  2.1执行安装[root@node12 mysql]# rpm -ivh ./*.rpm --nodeps --force 2.2修改密码无密码登录:mysql -u root由于权限问题可能会报错:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)更改权限:chown root /var/lib/mysql/然后,重启服务:systemctl restart mysqld在登录msyql: mysql -u root修改密码:mysql > use mysql;mysql > update user set password=password('123456') where user='root';mysql > exit;重启mysql服务:systemctl restart mysqld 2.3建库并授权在MySQL上安装zabbix数据库和用户,授权远程登录# mysql -uroot -p123456mysql> create database zabbix character set utf8 collate utf8_bin;mysql> grant all privileges on *.* to root@localhost identified by '123456';mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';mysql> quit; 3安装php【安装包来源】yum install --downloadonly --downloaddir=/opt/php php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash安装包 3.1执行安装[root@node12 php]# rpm -ivh ./*.rpm --nodeps --force 3.2测试PHPcd  /var/www/html/ vi info.php加入:<?php        phpinfo();?> systemctl restart httpd 3.3浏览器访问192.168.100.12/info.php   4.安装zabbix【依赖包来源】yum install --downloadonly --downloaddir=/opt/zabbix net-snmp-devel libxml2-devel  libevent libevent-devel curl-devel mysql-devel 依赖包,注意其中有一个是zabbix的源码包  4.1安装依赖[root@node12 zabbix]# rpm -ivh ./*.rpm --nodeps --force 4.2解压zabbix[root@node12 zabbix]# tar -zvxf zabbix-3.4.15.tar.gz -C /opt/install/ 4.3进入解压目录[root@node12 zabbix]# cd /opt/install/zabbix-3.4.15/ 4.4编译./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql  --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2注意:此时编译会出错,因为没有编译环境,所以编译之前先安装编译环境 编译环境包  4.5安装编译环境包[root@node12 gcc]# rpm -ivh ./*.rpm --nodeps --force 4.6再次编译./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql  --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml24.7安装make && make install 4.8创建用户和用户组:groupadd zabbixuseradd -g zabbix zabbix 4.9导入数据到数据库cd zabbix-3.4.15/database/mysql/ mysql -uzabbix -pzabbix  zabbix < schema.sqlmysql -uzabbix -pzabbix  zabbix < images.sqlmysql -uzabbix -pzabbix  zabbix < data.sql 进入mysql,查看zabbix的表导入进去没use zabbix;how tables; 4.10创建日志目录:cd /usr/local/zabbixmkdir logschown zabbix:zabbix logs 4.11修改zabbix_server.confvi /usr/local/zabbix/etc/zabbix_server.conf修改日志的路径LogFile=/usr/local/zabbix/logs/zabbix_server.log 修改DB参数DBName=zabbixDBUser=zabbixDBPassword=zabbix4.12 修改zabbix_agent.confvi /usr/local/zabbix/etc/zabbix_agentd.confServer=127.0.0.1ServerActive=127.0.0.1 (指向zabbix-server的主机)Hostname=xx  (本地主机名) 4.13 zabbix服务启动脚本cd /opt/install/zabbix-3.4.15/cp misc/init.d/fedora/core/zabbix_*  /etc/init.d/将启动脚本的路径修改为自己安装的位置:修改服务器端启动文件# vi /etc/init.d/zabbix_server将BASEDIR=/usr/local/替换为BASEDIR=/usr/local/zabbix(以之前编译的位置为准)修改客户器端启动文件:# vi /etc/init.d/zabbix_agentd将BASEDIR=/usr/local/替换为BASEDIR=/usr/local/zabbix(以之前编译的位置为准) 4.14 启动zabbix_server 和 zabiix_agent服务(测试是否有效)# /usr/local/zabbix/sbin/zabbix_server# /usr/local/zabbix/sbin/zabbix_agentd设置zabbix server 和zabbix agentd开机自动启动chkconfig --add zabbix_serverchkconfig --add zabbix_agentdchkconfig  zabbix_server onchkconfig  zabbix_agentd on /etc/init.d/zabbix_server restart/etc/init.d/zabbix_agentd restart 4.15前端Web配置mkdir /var/www/html/zabbix/cd /opt/install/zabbix-3.4.15/cp -a ./frontends/php/*  /var/www/html/zabbixchown -R zabbix.zabbix  /var/www/html/zabbix/systemctl restart httpd 4.16访问  4.17解决红色Failvi /etc/php.inipost_max_size = 8M-->16Mmax_execution_time = 30-->300max_input_time = 60-->300#在配置文件878行添加亚洲时区date.timezone = Asia/Shanghaisystemctl restart httpd 4.18 Zabbix配置可以看到显示的ok信息 继续下一步配置信息选则MySQL和端口,配置zabbix数据库信息 然后就下一步就好了。最后会显示如下信息,无法安装配置文件,按照提示下载文件然后上传到提示目录下即可。 下载文件(zabbix.conf.php)上传到指定文件目录解决乱码cd  /var/www/html/zabbix/fonts上传字体文件到这个文件夹(在本地/opt/data)

    2020-10-09 詹学伟 专业交流 58 0