声明
1)该文章整理自网上的大牛和专家无私奉献的资料,具体引用的资料请看参考文献。
2)本文仅供学术交流,非商用。如果某部分不小心侵犯了大家的利益,还望海涵,并联系博主删除。
3)博主才疏学浅,文中如有不当之处,请各位指出,共同进步,谢谢。
4)此属于第一版本,若有错误,还需继续修正与增删。还望大家多多指点。大家都共享一点点,一起为祖国科研的推进添砖加瓦。
1 安装包路径放在 /usr/local/ 下 2 自启动systemctl文件放在 /usr/lib/systemd/system/ 下 3 Centos 7之前使用service,7之后使用 systemmctl 4 本笔记基于 Centos 7.2 版本整理,适用于7.0以上版本 5 自启动测试全部成功 6 未解决:systemctl 启动顺序怎么设置,设置after测试并没有用
一:安装 JDK
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html tar -xvf jdk-8u162-linux-x64.tar.gz -C /usr/local/ vim /etc/profile #################################################### export JAVA_HOME=/usr/local/jdk1.8.0_162 export JRE_HOME=/usr/local/jdk1.8.0_162/jre export CLASSPATH=.:$JAVA_HOME/lib$:JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin/$JAVA_HOME:$PATH ##################################################### 保存后退出 source /etc/profile java -version
二:安装 Mysql
1 https://downloads.mysql.com/archives/community/ 2 tar -xvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ 3 mv xxx mysql 4 创建mysql用户组及其用户 5 mkdir /usr/local/mysql/data 6 groupadd mysql 7 useradd -r -g mysql mysql 8 修改当前目录拥有者为mysql用户 9 cd mysql 10 chown -R mysql:mysql ./ 11 初始化数据 12 ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ 13 此处会生成一个密码,记录下来,不然后面无法登陆 14 cd /usr/local/mysql 15 ./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data 16 上传该配置文件到 /etc/my.cnf 17 mkdir -p /var/lib/mysqld 18 chown mysql:mysql /var/lib/mysqld 19 vim /etc/profile 20 ############################################# 21 export PATH=$PATH:/usr/local/mysql/bin 22 ############################################# 23 保存后退出 24 source /etc/profile 25 添加 mysql 为服务并开机自启动 26 touch /usr/lib/systemd/system/mysql.service 27 vim /usr/lib/systemd/system/mysql.service 28 ############################################## 29 [Unit] 30 Description=MySQL Server 31 After=network.target remote-fs.target nss-lookup.target 32 33 [Service] 34 User=mysql 35 Group=mysql 36 Type=simple 37 ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf 38 LimitNOFILE = 5000 39 Restart=always 40 #RestartPreventExitStatus=1 41 #PrivateTmp=false 42 43 [Install] 44 WantedBy=multi-user.target 45 ############################################## 46 chmod 777 /usr/lib/systemd/system/mysql.service 47 systemctl daemon-reload 48 开机自启动 systemctl enable mysql.service 49 启动 systemctl start mysql.service 50 默认端口 3306 51 进入 mysql 52 /usr/local/mysql/bin/mysql -uroot -p 53 修改密码 54 mysql> set password for root@localhost = password('Zhaoweijun100'); 55 mysql> update mysql.user set host = '%' where user = 'root'; 56 mysql> flush privileges; 57 mysql> exit; 58 59 安装到此结束,以下是填坑时的经验,如果没有碰到,请忽略。 60 正常启动 61 /usr/local/mysql/bin/mysqld --user=mysql 62 以safe守护进程模式启动mysql,非正常停止时会自动重启 63 /usr/local/mysql/bin/mysqld_safe --user=mysql & 64 注意:使用 mysqld_safe起的mysql是个守护进程,如果关闭mysql需要执行 65 mysqladmin -h127.0.0.1 -uroot -p shutdown 66 注意:service 自启动无法开启原因和解决方案 67 /var/run/mysqld 目录每次重启后都需要手动去创建, 68 是因为/var/run/目录下建立文件夹是在内存中,故每次重启后内存被清空导致/var/run/mysqld 也被清除,从而导致无法启动mysql。 69 vim /etc/init.d/mysqld 70 找到下面字段 71 get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid" 72 修改为 73 get_mysql_option mysqld_safe pid-file "/var/lib/mysql/mysqld.pid" 74 保存后退出,执行 75 systemctl daemon-reload 76 https://www.cnblogs.com/ivictor/p/5146247.html
三:安装 Redis
1 https://redis.io/download 2 tar -xvf redis-4.0.8.tar.gz -C /usr/local/ 3 mv xxx redis 4 cd /usr/local/redis 5 make 6 cd src 7 make install 8 cd /usr/local/redis 9 mkdir bin 10 mkdir log 11 touch ./log/redis.log 12 cd /usr/local/redis/src 13 mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server /usr/local/redis/bin 14 修改配置文件 /usr/local/redis/redis.conf 15 daemonize no => yes #后台运行 16 bind 0.0.0.0 17 requirepass weijunZhao 18 logfile "/usr/local/redis/log/redis.log" 19 dir "/usr/local/redis/" 20 如果redis设置定时任务需要开启 21 notify-keyspace-events "KEA" 22 添加 Redis 为服务并开机自启动 23 touch /usr/lib/systemd/system/redis-server.service 24 vim /usr/lib/systemd/system/redis-server.service 25 ############################################## 26 [Unit] 27 Description=Redis-Server Manager 28 After=network.target remote-fs.target nss-lookup.target 29 30 [Service] 31 Type=forking 32 ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf 33 Restart=always 34 #PrivateTmp=true 35 36 [Install] 37 WantedBy=multi-user.target 38 ############################################## 39 chmod 777 /usr/lib/systemd/system/redis-server.service 40 systemctl daemon-reload 41 开机自启动 systemctl enable redis-server.service 42 启动 systemctl start redis-server.service 43 默认端口号 6379 44 45 注意:安装过程中出现 adlist.o 错误时,一般是没有gcc,需要安装依赖 46 http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/ 47 放在文件夹 gcc 中,进入执行 48 rpm -Uvh *.rpm --nodeps --force 49 即可 50 删除 redis 然后在重新解压make,否则报TMD一堆错 51 make 报错还有种方式: 52 make MALLOC=libc 53 直接运行命令 54 运行Redis服务端 55 ./bin/redis-server /usr/local/redis/redis.conf 56 运行Redis客户端 57 ./bin/redis-cli
四:安装 Zookeeper
1 https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 2 tar -xvf zookeeper-3.4.10.tar.gz -C /usr/local/ 3 mv xxx zookeeper 4 cd zookeeper 5 mkdir data 6 mkdir log 7 cp ./conf/zoo_sample.cfg ./conf/zoo.cfg 8 vim ./conf/zoo.cfg 9 ############################################# 10 tickTime=2000 11 dataDir=/usr/local/zookeeper/data 12 dataLogDir=/usr/local/zookeeper/log 13 clientPort=2181 14 initLimit=5 15 syncLimit=2 16 ############################################ 17 保存后退出 18 vim /etc/profile 19 ############################################ 20 export ZOOKEEPER=/usr/local/zookeeper 21 export PATH=$ZOOKEEPER/bin:$PATH 22 ############################################ 23 保存后退出 24 source /etc/profile 25 添加 zookeeper 为服务并开机自启动 26 touch /usr/lib/systemd/system/zookeeper.service 27 vim /usr/lib/systemd/system/zookeeper.service 28 ############################################ 29 [Unit] 30 Description=Zookeeper Service 31 After=network.target 32 ConditionPathExists=/usr/local/zookeeper/conf/zoo.cfg 33 34 [Service] 35 Type=forking 36 Environment=JAVA_HOME=/usr/local/jdk1.8.0_162 37 ExecStart=/usr/local/zookeeper/bin/zkServer.sh start 38 ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop 39 ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart 40 Restart=always 41 42 [Install] 43 WantedBy=multi-user.target 44 ############################################ 45 chmod 777 /usr/lib/systemd/system/zookeeper.service 46 systemctl daemon-reload 47 开机自启动 systemctl enable zookeeper.service 48 启动 systemctl start zookeeper.service 49 默认端口 2181 50 51 直接启动命令 52 ./bin/zkServer.sh start 53 ./bin/zkServer.sh stop
五:安装 Kafka
1 http://kafka.apache.org/downloads 2 tar -xvf kafka_2.11-0.10.1.1.tgz -C /usr/local/ 3 mv xxx kafka 4 cd kafka 5 mkdir log 6 vim ./config/server.properties 7 ############################################ 8 log.dirs=/usr/local/kafka/log 9 ############################################ 10 注意:如果调用服务和kafka不在同一个服务器,需要开启广播 11 server.properties 12 ############################################ 13 advertised.listeners=PLAINTEXT://xxx:9092 14 ############################################ 15 添加 Kafka 为服务并开机自启动 16 touch /usr/lib/systemd/system/kafka.service 17 vim /usr/lib/systemd/system/kafka.service 18 ############################################ 19 [Unit] 20 Description=kafka server 21 After=network.target remote-fs.target nss-lookup.target 22 23 [Service] 24 Type=forking 25 Environment=JAVA_HOME=/usr/local/jdk1.8.0_162 26 ExecStart=/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties 27 ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh /usr/local/kafka/config/server.properties 28 Restart=always 29 30 [Install] 31 WantedBy=multi-user.target 32 ############################################ 33 chmod 777 /usr/lib/systemd/system/kafka.service 34 systemctl daemon-reload 35 开机自启动 systemctl enable kafka.service 36 启动 systemctl start kafka.service 37 停止 systemctl stop kafka.service 38 默认端口 9092 39 40 直接启动命令 41 nohup ./bin/kafka-server-start.sh ./config/server.properties &
六:安装 Nginx
1 解压 2 tar -xvf /usr/local/nginx-1.15.2.tar.gz -C /usr/local/ 3 mv xxx nginx 4 cd nginx 5 加载配置(注意:/nginx.conf 不是 /conf/nginx.conf) 6 ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf 7 make 8 make install 9 在web地址栏输入 localhost:80 显示 nginx 欢迎界面 10 成功后显示nginx的所有路径 11 添加 nginx 为服务并开机自启动 12 touch /usr/lib/systemd/system/nginx.service 13 vim /usr/lib/systemd/system/nginx.service 14 ######################################## 15 [Unit] 16 Description=nginx - high performance web server 17 After=network.target remote-fs.target nss-lookup.target 18 19 [Service] 20 Type=forking 21 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 22 ExecReload=/usr/local/nginx/sbin/nginx -s reload 23 ExecStop=/usr/local/nginx/sbin/nginx -s stop 24 Restart=always 25 26 [Install] 27 WantedBy=multi-user.target 28 ######################################## 29 chmod 777 /usr/lib/systemd/system/nginx.service 30 systemctl daemon-reload 31 开机自启动 systemctl enable nginx.service 32 启动 systemctl start nginx.service 33 默认端口 80 34 35 直接启动命令 36 ./sbin/nginx -c ./conf/nginx.conf 37 在不停止 nginx 的情况下加载配置文件 38 ./sbin/nginx -s reload 39 40 其他在线安装方式(不推荐) 41 在线Ubuntu安装 42 sudo apt-get update 43 sudo apt-get install nginx 44 /usr/sbin/nginx:主程序 45 /etc/nginx:存放配置文件 46 /usr/share/nginx:存放静态文件 47 /var/log/nginx:存放日志 48 在线centos安装 49 sudo yum install -y nginx 50 启动:nginx -c nginx.conf 51 网站文件存放默认目录 52 /usr/share/nginx/html 53 网站默认站点配置 54 /etc/nginx/conf.d/default.conf 55 自定义Nginx站点配置文件存放目录 56 /etc/nginx/conf.d/ 57 Nginx全局配置 58 /etc/nginx/nginx.conf 59 安装包安装 60 依赖环境: 61 yum install gcc-c++ 62 yum install -y pcre pcre-devel 63 yum install -y zlib zlib-devel 64 yum install -y openssl openssl-devel 65 本地安装依赖环境: 66 检测 rpm -qa pcre 67 https://centos.pkgs.org/7/centos-x86_64/pcre-devel-8.32-17.el7.x86_64.rpm.html 68 安装 rpm -ivh pcre-devel-8.32-17.el7.x86_64.rpm 69 检测 rpm -qa zlib 70 https://centos.pkgs.org/7/centos-x86_64/zlib-devel-1.2.7-17.el7.x86_64.rpm.html 71 安装 rpm -ivh zlib-devel-1.2.7-17.el7.x86_64.rpm 72 如果报错使用强制安装指令 73 rpm -ivh pcre-devel-8.32-17.el7.x86_64.rpm --nodeps --force 74 rpm -ivh zlib-devel-1.2.7-17.el7.x86_64.rpm --nodeps --force
七:安装 Tomcat
1 http://tomcat.apache.org/download-80.cgi 2 tar -xvf apache-tomcat-8.5.11.tar.gz -C /usr/tomcat/ 3 mv xxx tomcat 4 cd tomcat 5 vim ./bin/setclasspath.sh 6 ####################################### 7 export JAVA_HOME=/usr/local/jdk1.8.0_121 8 export JRE_HOME=/usr/local/jdk1.8.0_121/jre 9 ####################################### 10 以上这一步不是必须的 11 项目存放目录 12 /usr/local/tomcat/webapps/ 13 配置文件地址 14 ./conf/server.xml 15 添加 tomcat 为服务并开机自启动 16 touch /usr/lib/systemd/system/tomcat.service 17 vim /usr/lib/systemd/system/tomcat.service 18 ######################################## 19 [Unit] 20 Description=Tomcat Service 21 After=syslog.target network.target 22 23 [Service] 24 Type=forking 25 Environment=JAVA_HOME=/usr/local/jdk 26 #PIDFile=/usr/local/tomcat/tomcat.pid 27 ExecStart=/usr/local/tomcat/bin/startup.sh 28 ExecReload=/bin/kill -s HUP $MAINPID 29 ExecStop=/bin/kill -s QUIT $MAINPID 30 PrivateTmp=true 31 32 [Install] 33 WantedBy=multi-user.target 34 ######################################## 35 chmod 777 /usr/lib/systemd/system/tomcat.service 36 systemctl daemon-reload 37 开机自启动 systemctl enable tomcat.service 38 启动 systemctl start tomcat.service 39 默认端口号 8080 40 41 直接启动命令 42 ./bin/startup.sh
八:安装 Go
1 https://blog.csdn.net/zxs9999/article/details/78874807 2 tar -xvf go1.10.1.linux-amd64.tar.gz -C /usr/local/ 3 mv xxx go 4 cd / 5 mkdir ws_go 6 vim /etc/profile 7 ############################################## 8 export PATH=$PATH:/usr/local/go/bin 9 export GOPATH=/ws_go 10 ############################################## 11 如果安装目录不在 /usr/local/ 下,需要设置 GOROOT 12 ############################################## 13 export GOROOT=/usr/go 14 export PATH=$PATH:$GOROOT/bin 15 ############################################## 16 source /etc/profile 17 验证 18 go version
九:安装 MongoDB
1 https://www.mongodb.com/download-center#production 2 tar –zxvf mongodb-linux-x86_64-rhel62-3.2.4.gz -C /usr/local/ 3 mv xxx mongodb 4 vim /etc/profile 5 ############################################## 6 export MONGODB_HOME=/usr/local/mongodb 7 export PATH=$PATH:$MONGODB_HOME/bin 8 ############################################# 9 source /etc/profile 10 cd mongodb 11 mkdir db 用于存放数据库 12 touch mongodb.conf 创建 conf 文件 13 mkdir logs 用于存放日志 14 touch mongodb.log 15 设置 logs 和 db 的权限 16 启动 17 ./bin/mongod --config ./mongodb.conf 18 waiting for...代表成功 19 连接 mongodb 20 ./mongo 21 /usr/local/mongodb/mongodb.conf 创建conf添加以下内容 22 ################################################### 23 port=27017 #端口号 24 dbpath=/usr/local/mongodb/db #数据库存放路径 25 logpath=/usr/local/mongodb/logs/mongodb.log #日志输出文件路径 26 logappend=true #日志输出方式为追加方式 27 pidfilepath=/usr/local/mongodb/mongo.pid 28 fork=true #设置后台运行 29 shardsvr=true 30 #auth=true #开启认证 31 #noauth=true #不开启认证 32 bind_ip=0.0.0.0 #开通外部访问 33 ######################################################### 34 设置开机自启动 35 touch /usr/lib/systemd/system/mongodb.service 36 mongodb.service 设置如下: 37 ################################################# 38 [Unit] 39 Description=mongodb 40 After=network.target remote-fs.target nss-lookup.target 41 42 [Service] 43 Type=forking 44 ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongodb.conf 45 ExecReload=/bin/kill -s HUP $MAINPID 46 ExecStop=/usr/local/mongodb/bin/mongod --shutdown -f /usr/local/mongodb/mongodb.conf 47 PrivateTmp=true 48 49 [Install] 50 WantedBy=multi-user.target 51 ##################################################### 52 chmod 777 /usr/lib/systemd/system/mongodb.service 53 systemctl daemon-reload 54 注册到开机启动 systemctl enable mongodb.service 55 启动 systemctl start mongodb.service 56 57 创建账号密码,先stop 58 /usr/local/mongodb/mongodb.conf 修改配置文件添加 59 auth=true (打开这个设置,默认关闭,打开后开启安全验证) 60 use admin //用admin身份 61 db.createUser({user:"root",pwd:"root123",roles:["root"]})//创建账号 62 db.auth("root","rootzwj")//就可以进入了 63 默认端口 27017
十:安装 Rar,Zip 包
1 https://www.rarlab.com/rar/rarlinux-x64-5.5.0.tar.gz 2 tar -zxvf rarlinux-x64-5.5.0.tar.gz -C /usr/local/ 3 cd rar 4 make 5 即可 6 常用指令 7 解压rar包 rar x bb.rar
十一:java 自启动
1 假设 jar 包的路径为 /usr/service/test/test.jar 2 编写启动脚本:test-start.sh 3 ################################################ 4 #!/bin/sh 5 6 export JAVA_HOME=/usr/local/jdk1.8.0_162 7 export PATH=$JAVA_HOME/bin:$PATH 8 9 nohup java -jar /usr/service/test/test.jar > /usr/service/test/test.log 2>&1 & 10 echo $! > /var/run/test.pid 11 ################################################ 12 编写停止脚本:test-stop.sh 13 ################################################ 14 #!/bin/sh 15 16 PID=$(cat /var/run/test.pid) 17 kill -9 $PID 18 rm -fr /var/run/test.pid 19 ################################################ 20 touch /usr/lib/systemd/system/java-test.service 21 ############################################### 22 [Unit] 23 Description=TestJava 24 After=syslog.target network.target remote-fs.target nss-lookup.target 25 26 [Service] 27 Type=forking 28 ExecStart=/usr/service/test/start.sh 29 ExecStop=/usr/service/test/stop.sh 30 PrivateTmp=true 31 Restart=always 32 33 [Install] 34 WantedBy=multi-user.target 35 ############################################### 36 chmod 777 /usr/lib/systemd/system/java-test.service 37 systemctl daemon-reload 38 注意:一定要修改 jar 包路径的权限 39 chmod -R 777 /usr/service/ 40 注册到开机启动 systemctl enable java-test.service 41 启动 systemctl start java-test.service 42 关闭 systemctl stop java-test.service 43 注意:在win和Linux之间的文件格式不一样 44 vim xxx.sh 之后查看文件格式 45 :set ff 46 Linux的设置为 47 :set ff=unix 48 即可 49 注意:当用 supervisord 管理 java 程序时,要在 supervisor 的配置文件里添加JAVA_HOME 50 不需要 start.sh 和 stop.sh,修改权限 51 conf 文件为 52 ####################################################### 53 [program:java-test] 54 command = java -jar /usr/service/test/test.jar 55 autostart=true 56 startsecs=3 57 startretries=3 58 autorestart=true 59 exitcodes=0,2 60 stopsignal=TERM 61 stopwaitsecs=10 62 redirect_stderr=false 63 stdout_logfile=/usr/service/logstash/log-info-java-test.log 64 stdout_logfile_maxbytes=50MB 65 stdout_logfile_backups=10 66 stdout_capture_maxbytes=0 67 stdout_events_enabled=true 68 stderr_logfile=/usr/service/logstash/log-error-yum-java-test.log 69 stderr_logfile_maxbytes=50MB 70 stderr_logfile_backups=1 71 stderr_capture_maxbytes=0 72 stderr_events_enabled=false 73 ####################################################### 74 启动 supervisor 即可
十二:安装 supervisor (可以管理go,java等进程)
1 假设 supervisord 的路径为 /data/go/supervisor/supervisord 2 编写启动脚本:startup.sh 3 ################################################# 4 #!/bin/sh 5 6 export JAVA_HOME=/usr/local/jdk1.8.0_162 7 export PATH=$JAVA_HOME/bin:$PATH 8 9 nohup /usr/service/supervisor/supervisord -c=/usr/service/supervisor/supervisor.conf > /usr/service/logstash/log_supervisord.log 2>&1 & 10 echo $! > /var/run/supervisord.pid 11 ################################################# 12 编写停止脚本:stop.sh 13 ################################################# 14 #!/bin/sh 15 16 PID=$(cat /var/run/supervisord.pid) 17 kill -9 $PID 18 rm -fr /var/run/supervisord.pid 19 ################################################# 20 添加到系统服务: 21 touch /usr/lib/systemd/system/supervisord.service 22 supervisord.service 设置如下: 23 ################################################# 24 [Unit] 25 Description=supervisord 26 After=network.target remote-fs.target nss-lookup.target 27 28 [Service] 29 Type=forking 30 # Environment=JAVA_HOME=/usr/local/jdk1.8.0_162 31 ExecStart=/usr/service/supervisor/startup.sh 32 ExecStop=/usr/service/supervisor/stop.sh 33 PrivateTmp=true 34 Restart=always 35 36 [Install] 37 WantedBy=multi-user.target 38 ##################################################### 39 chmod 777 /usr/lib/systemd/system/supervisord.service 40 systemctl daemon-reload 41 注册到开机启动 systemctl enable supervisord.service 42 chmod -R 777 /usr/service 43 启动 systemctl start supervisord.service 44 关闭 systemctl stop supervisord.service 45 注意:supervisord/conf里的配置文件 46 java需要加载单独配置文件时,需要注明路径,如下: 47 [program:user] 48 directory = /usr/service/user/ 49 command = java -jar ./user.jar
十三:安装 ZeroMQ
wget http://download.zeromq.org/zeromq-4.0.4.tar.gz tar zvxf zeromq-4.0.4.tar.gz -C /usr/local/ mv zeromq-4.0.4 zeromq cd zeromq 先安装GCC, G++ sudo yum install gcc sudo yum install gcc-c++ 编译安装 ./configure 安装成功
十四:安装 EMQTT(客户端服务端二合一)
1 http://www.emqtt.com/downloads 2 emqx 为开发版 3 emqttd 为稳定版 4 chmod -R 777 /usr/local/emqttd 5 加入系统服务 6 添加到系统服务: 7 touch /usr/lib/systemd/system/emqttd.service 8 vim /usr/lib/systemd/system/emqttd.service 9 emqttd.service 设置如下: 10 ################################################# 11 [Unit] 12 Description=emqttd 13 After=network.target remote-fs.target nss-lookup.target 14 15 [Service] 16 Type=forking 17 Environment=HOME=/usr/local/emqttd 18 ExecStart=/usr/local/emqttd/bin/emqttd start 19 ExecReload=/usr/local/emqttd/bin/emqttd reboot 20 ExecStop=/usr/local/emqttd/bin/emqttd stop 21 PrivateTmp=true 22 Restart=always 23 24 [Install] 25 WantedBy=multi-user.target 26 ################################################ 27 chmod 777 /usr/lib/systemd/system/emqttd.service 28 systemctl daemon-reload 29 注册到开机启动 systemctl enable emqttd.service 30 修改 emqttd 的目录权限后再开机 31 启动 systemctl start emqttd.service 32 33 直接启动指令 34 ./bin/emqttd start 35 常用端口号
十五:安装 Logstash(java,测试至少需要500M内存)
1 https://www.elastic.co/downloads/logstash 2 2019-04-11 以最新版 logstash-7.0.0.tar.gz 为例 3 解压后 4 cd /usr/local/logstash 5 修改配置文件 ./config/logstash.yml ,设置 6 ==================================== 7 http.host: 0.0.0.0 8 #设置节点名称,一般写主机名 9 node.name: cpy04.dev.xjh.com 10 #创建logstash 和插件使用的持久化目录 11 path.data: /usr/local/logstash/data 12 #开启配置文件自动加载 13 config.reload.automatic: true 14 #定义配置文件重载时间周期 15 config.reload.interval: 10s 16 http.host: "0.0.0.0" 17 log.level: info 18 path.logs: /usr/local/logstash/logs 19 ======================================== 20 新建配置文件 logstash.conf(配置文件名字任意) 21 ======================================== 22 input { 23 file { 24 path => ["/usr/service/logstash"] 25 type => "service_log" 26 start_position => "beginning" 27 } 28 } 29 30 filter { 31 32 } 33 34 output { 35 elasticsearch { 36 hosts => ["http://106.12.78.98:9200"] 37 index => "sz01-106.12.73.138" 38 } 39 } 40 ========================================= 41 添加到系统服务开机自启动(特殊) 42 执行一条指令 43 /usr/local/logstash/bin/system-install 44 chmod -R 777 /usr/local/logstash 45 /usr/local/logstash/config/startup.options systemd 46 默认会在 /etc/systemd/system/logstash.service 下生成 47 自动生成的是以 logstash 用户权限,修改 logstash.service 48 修改用户和组和conf文件 49 logstash.service 设置如下: 50 ########################################## 51 [Unit] 52 Description=logstash 53 54 [Service] 55 Type=forking 56 User=root 57 Group=root 58 Environment=JAVA_HOME=/usr/local/jdk1.8.0_162 59 ExecStart=/usr/local/logstash/bin/logstash -f /usr/local/logstash/logstash.conf 60 Restart=always 61 62 [Install] 63 WantedBy=multi-user.target 64 ########################################## 65 chmod 777 /etc/systemd/system/logstash.service 66 systemctl daemon-reload 67 systemctl enable logstash.service 68 systemctl start logstash.service 69 systemctl status logstash.service 70 默认端口号 71 9600 72 73 直接启动命令 74 启动 bin/logstash -f logstash.conf 75 后台运行 nohup ./bin/logstash -f logstash.conf &
十六:Elastic APM-Server
1 安装前提:jdk 2 下载地址: 3 https://www.elastic.co/cn/downloads/apm 4 解压 5 重命名 6 mv xxx apm-server 7 修改 apm-server.yml 配置文件 8 apm-server: 9 host: "0.0.0.0:8200" #内网测试此处如果设置为localhost会有问题 10 rum: 11 enabled: true 12 output.elasticsearch: 13 hosts: ["xxx:9200"] 14 Linux 运行 15 nohup ./apm-server & 16 端口 8200 17 加入系统服务开机自启动 18 touch /usr/lib/systemd/system/apm-server.service 19 apm-server.service 设置如下: 20 ################################################# 21 [Unit] 22 Description=apm-server 23 After=network.target remote-fs.target nss-lookup.target 24 25 [Service] 26 Type=simple 27 ExecStart=/usr/local/apm-server/apm-server -e -c /usr/local/apm-server/apm-server.yml 28 29 [Install] 30 WantedBy=multi-user.target 31 ################################################ 32 chmod 777 /usr/lib/systemd/system/apm-server.service 33 systemctl daemon-reload 34 注册到开机启动 systemctl enable apm-server.service 35 启动 systemctl start apm-server.service 36 关闭 systemctl stop apm-server.service
十七:安装 Elsearch(java,测试至少需要1.3G的内存)
1 https://www.elastic.co/downloads/elasticsearch 2 解压后重命名 3 mv xxx elasticsearch 4 mkdir /usr/local/elasticsearch/data 5 mkdir /usr/local/elasticsearch/logs 6 需要修改config/elasticsearch.yml中配置文件 7 cluster.name: aliyun-elastic 8 node.name: node-1 9 path.data: /usr/local/elasticsearch/data 10 path.logs: /usr/local/elasticsearch/logs 11 network.host: 0.0.0.0 12 http.port: 9200 13 cluster.initial_master_nodes: ["node-1"] 14 在Linux下,由于安全考虑不予许使用root用户启动 15 先创建用户组和用户 16 groupadd elsearch 17 useradd elsearch -g elsearch -p elasticsearch 18 chown -R elsearch:elsearch /usr/local/elasticsearch 19 切换用户 20 su elsearch 21 cd /usr/local/elasticsearch 22 ./bin/elasticsearch 23 nohup ./bin/elasticsearch & 24 默认端口号 9200 和 9300 25 如果碰到问题 26 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 27 在root用户下,在 /etc/sysctl.conf 的最后一行添加 28 vm.max_map_count=262144 29 然后执行 sysctl -p 30 查看修改是否成功 31 sysctl -a|grep vm.max_map_count 32 重启 elasticsearch 即可 33 添加到系统服务: 34 touch /usr/lib/systemd/system/elastic.service 35 elastic.service 设置如下: 36 ################################################# 37 [Unit] 38 Description=elastic 39 After=network.target remote-fs.target nss-lookup.target 40 41 [Service] 42 # 此处必须是 simple 43 Type=simple 44 User=elsearch 45 Group=elsearch 46 Environment=ES_HOME=/usr/local/elasticsearch 47 Environment=ES_PATH_CONF=/usr/local/elasticsearch/config 48 Environment=PID_DIR=/usr/local/elasticsearch 49 # EnvironmentFile=/etc/sysconfig/elasticsearch 50 # WorkingDirectory=/opt/elasticsearch 51 52 ExecStart=/usr/local/elasticsearch/bin/elasticsearch 53 54 StandardOutput=journal 55 StandardError=inherit 56 LimitNOFILE=65536 57 LimitNPROC=4096 58 LimitAS=infinity 59 LimitFSIZE=infinity 60 TimeoutStopSec=0 61 KillSignal=SIGTERM 62 KillMode=process 63 SendSIGKILL=no 64 SuccessExitStatus=143 65 66 [Install] 67 WantedBy=multi-user.target 68 ################################################ 69 chmod 777 /usr/lib/systemd/system/elastic.service 70 systemctl daemon-reload 71 注册到开机启动 systemctl enable elastic.service 72 启动 systemctl start elastic.service 73 关闭 systemctl stop elastic.service
十八:安装 kibana
1 https://www.elastic.co/downloads/kibana 2 修改 kibana.yml 配置文件,添加 3 server.port: 5601 4 server.host: "0.0.0.0" 5 elasticsearch.hosts: ["http://xxxx:9200"] #内网测试此处localhost页面会打不开 6 Linux 运行 7 nohup ./bin/kibana & 8 端口 5601 9 加入系统服务开机自启动 10 touch /usr/lib/systemd/system/kibana.service 11 kibana.service 设置如下: 12 ################################################# 13 [Unit] 14 Description=kibana 15 After=network.target remote-fs.target nss-lookup.target 16 17 [Service] 18 # 此处必须是 simple 19 Type=simple 20 ExecStart=/usr/local/kibana/bin/kibana 21 22 [Install] 23 WantedBy=multi-user.target 24 ################################################ 25 chmod 777 /usr/lib/systemd/system/kibana.service 26 systemctl daemon-reload 27 注册到开机启动 systemctl enable kibana.service 28 启动 systemctl start kibana.service 29 关闭 systemctl stop kibana.service
十九:安装 filebeat(go)
1 下载地址 2 https://www.elastic.co/cn/downloads/beats/filebeat 3 配置文件 4 filebeat.yml 5 启动 6 nohup ./filebeat -c filebeat.yml & 7 查看 8 ps -aux | grep filebeat 9 常用配置: 10 enabled: true 11 paths: 12 - /usr/service/logstash/*.log* 13 tags: ["SH002-"] 14 output.elasticsearch: 15 hosts: ["localhost:9200"] 16 添加到系统服务: 17 touch /usr/lib/systemd/system/filebeat.service 18 filebeat.service 设置如下: 19 ################################################# 20 [Unit] 21 Description=filebeat 22 After=network.target remote-fs.target nss-lookup.target 23 24 [Service] 25 Type=simple 26 ExecStart=/usr/local/filebeat/filebeat -e -c /usr/local/filebeat/filebeat.yml 27 28 [Install] 29 WantedBy=multi-user.target 30 ################################################ 31 chmod 777 /usr/lib/systemd/system/filebeat.service 32 systemctl daemon-reload 33 注册到开机启动 systemctl enable filebeat.service 34 有可能报错提醒为: 35 chmod go-w /usr/local/filebeat/filebeat.yml 36 启动 systemctl start filebeat.service 37 关闭 systemctl stop filebeat.service
二十:安装 telnet
1 查看 2 rpm -q telnet 3 rpm -q telnet-server 4 rpm -q xinetd 5 下载地址 6 http://rpmfind.net/linux/rpm2html/search.php?query=telnet(x86-64) 7 http://www.rpmfind.net/linux/rpm2html/search.php?query=telnet-server(x86-64) 8 http://rpm.pbone.net/index.php3/stat/4/idpl/35493746/dir/centos_7/com/xinetd-2.3.15-13.el7.x86_64.rpm.html 9 三个文件分别为: 10 telnet-0.17-64.el7.x86_64.rpm 11 telnet-server-0.17-64.el7.x86_64.rpm 12 xinetd-2.3.15-13.el7.x86_64.rpm 13 安装软件包指令: 14 rpm -Uvh *.rpm --nodeps --force 15 修改文件/etc/xinetd.d/telnet来开启服务 16 disable = yes 为 disable = no 17 如果没有该文件,创建 18 touch /etc/xinetd.d/telnet 19 vim /etc/xinetd.d/telnet 20 ############################################ 21 # default: yes 22 # description: The telnet server servestelnet sessions; it uses \ 23 # unencrypted username/password pairs for authentication. 24 service telnet 25 { 26 flags = REUSE 27 socket_type = stream 28 wait = no 29 user = root 30 server =/usr/sbin/in.telnetd 31 log_on_failure += USERID 32 disable = no 33 } 34 ############################################ 35 systemctl restart xinetd.service 36 systemctl enable xinetd.service 37 systemctl enable telnet.socket
二十一:OSS 对象存储系统(Minio)
1 一个二进制文件 2 https://dl.minio.io/server/minio/release/linux-amd64/minio 3 chmod +x OSS 4 先启动,会生成一个 secret 和 key,分布式需要记住,或者固定指定这两个值 5 ./OSS server /data 6 停止 ctrl + c 7 8 加入系统服务 9 touch /usr/lib/systemd/system/oss.service 10 vim /usr/lib/systemd/system/oss.service 11 ################################################# 12 [Unit] 13 Description=oss 14 After=network.target remote-fs.target nss-lookup.target 15 16 [Service] 17 Type=simple 18 Environment=MINIO_ACCESS_KEY=BA3IZ8XP9THSFLQFPK82 19 Environment=MINIO_SECRET_KEY=Orwg3UaZj71v8he0dEfdmfILYYV1wLfIk+77yi1F 20 #ExecStart=/usr/local/oss/OSS server --address 127.0.0.1:80 /upload 21 ExecStart=/usr/local/oss/OSS server /upload 22 Restart=always 23 24 [Install] 25 WantedBy=multi-user.target 26 ################################################ 27 chmod 777 /usr/lib/systemd/system/oss.service 28 systemctl daemon-reload 29 systemctl enable oss.service 30 启动 systemctl start oss.service 31 默认端口号 9000
二十二:读写分离 mycat(1.6.5-release版本)
1 前提:安装 jdk 2 mysql 实现同步机制 3 下载地址: 4 https://github.com/MyCATApache/Mycat-download 5 解压 6 加入系统变量 7 vim /etc/profile 8 export MYCAT_HOME=/usr/local/mycat/ 9 source /etc/profile 10 修改配置文件 mycat/conf/ 下 11 修改配置文件 wrapper.conf ,设置 java 路径 12 wrapper.java.command=/usr/local/jdk1.8.0_162/bin/java 13 修改配置文件 server.xml,设置访问用户和访问权限 14 (根据需求修改,也可以不改) 15 修改配置文件 schema.xml 16 writeHost 和 readHost,删除其他无用的 writeHost 17 加入系统服务 18 touch /usr/lib/systemd/system/mycat.service 19 vim /usr/lib/systemd/system/mycat.service 20 ################################################# 21 [Unit] 22 Description=mycat 23 After=network.target remote-fs.target nss-lookup.target 24 25 [Service] 26 Type=forking 27 ExecStart=/usr/local/mycat/bin/mycat start 28 ExecStop=/usr/local/mycat/bin/mycat stop 29 Restart=always 30 31 [Install] 32 WantedBy=multi-user.target 33 ################################################ 34 chmod 777 /usr/lib/systemd/system/mycat.service 35 systemctl daemon-reload 36 systemctl enable mycat.service 37 启动 systemctl start mycat.service 38 默认端口号 8066 39 40 验证方法 41 mysql -uroot -P8066 -p123456 -h127.0.0.1 42 43 直接启动方式 44 ./bin/mycat start 45 ./bin/mycat stop