centOS安装Pythod;PHP;Git;Maven;MySQL;Apache2;Tomcat;RabbitMQ;Redis;Zookeeper;Kafka;ActiveMQ - 2877206/docs GitHub Wiki
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp
Python
https://www.liquidweb.com/kb/how-to-install-pip-on-centos-7/
Option #1: Install Pip with Yum, Step #1: Add the EPEL Repository Pip is part of Extra Packages for Enterprise Linux (EPEL), which is a community repository of non-standard packages for the RHEL distribution. First, we’ll install the EPEL repository:
rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Option #1: Install Pip with Yum, Step #2: The Installation As a matter of best practice we’ll update our packages:
yum -y update
Then let’s install python-pip and any required packages:
yum -y install python-pip
Git
# yum install git
Maven
cd /opt
http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
wgettar -xzvf apache-maven-3.3.1-bin.tar.gz
vi /etc/profile.d/maven.sh
export M2_HOME=/opt/apache-maven-3.3.9 export PATH=$M2_HOME/bin:$PATH} export PATH=$M2_HOME:$PATH
source /etc/profile
ldconfig
mkdir -p ~/.m2
rm -rf ~/.m2/settings.xml
mvn -version
MySQL
yum -y install mariadb-server mariadb
systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation
GRANT ALL PRIVILEGES ON . TO 'root'@'192.168.100.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
flush privileges;
mysql>GRANT ALL PRIVILEGES ON . TO 'root'@'%'WITH GRANT OPTION
//赋予任何主机访问数据的权限
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON . TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON . TO 'myuser'@'192.168.1.3'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
mysql> use mysql; Database changed mysql> select host,user,password from user; +-----------+------+-------------------------------------------+ | host | user | password | +-----------+------+-------------------------------------------+ | localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | +-----------+------+-------------------------------------------+
Apache2
yum -y install httpd systemctl start httpd.service systemctl enable httpd.service
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload
Tomcat
https://www.unixmen.com/install-apache-ant-maven-tomcat-centos-76-5/ wget http://mirror.sdunix.com/apache/tomcat/tomcat-8/v8.0.15/bin/apache-tomcat-8.0.15.zip
Extract it using command:
unzip apache-tomcat-8.0.15.zip
Move the extracted contents to /opt/ directory.
mv apache-tomcat-8.0.15/ /opt/tomcat
Setup Tomcat environment variable
Create a file called tomcat.sh under /etc/profile.d/ directory.
vi /etc/profile.d/tomcat.sh
Add the following contents:
#!/bin/bash CATALINA_HOME=/opt/tomcat PATH=$CATALINA_HOME/bin:$PATH export PATH CATALINA_HOME export CLASSPATH=.
Save and close the file. Make it executable using the following command.
chmod +x /etc/profile.d/tomcat.sh
Then, set the environment variables permanently by running the following command:
source /etc/profile.d/tomcat.sh
Now, we have to start the Tomcat server. Before starting Tomcat, give executable permission to the following script files.
chmod +x $CATALINA_HOME/bin/startup.sh chmod +x $CATALINA_HOME/bin/shutdown.sh chmod +x $CATALINA_HOME/bin/catalina.sh
Start Tomcat server by running the following command from your Terminal.
cd $CATALINA_HOME/bin ./startup.sh
redis
https://www.digitalocean.com/community/tutorials/how-to-configure-a-redis-cluster-on-centos-7 http://sharadchhetri.com/2014/10/04/install-redis-server-centos-7-rhel-7/ wget -r --no-parent -A 'epel-release-.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/e/ rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-.rpm yum install redis 1. /etc/redis.conf 2. /etc/redis-sentinel.conf
Now start the redis server after this.
systemctl start redis.service
Check the running status of redis server
systemctl status redis.service
To test the installation of Redis, use below given command
redis-cli ping
ss -nlp|grep redis
The above command is saying that we want redis-benchmark to run in quiet mode, with 1000 total requests, 10 parallel connections and pipeline 5 requests. For more information on running benchmarks for Redis, typing redis-benchmark --help in your terminal will print useful information with examples.
redis-benchmark -q -n 1000 -c 10 -P 5
Step 2 — Configure Redis Master
Now that Redis is up and running on our two-Droplet cluster, we have to edit their configuration files. As we will see, there are minor differences between configuring the master server and the slave.
Let's first start with our master.
Open /etc/redis.conf with your favorite text editor:
sudo vi /etc/redis.conf
Edit the following lines.
Set a sensible value to the keepalive timer for TCP: /etc/redis.conf
tcp-keepalive 60
Make the server accessible to anyone on the web by commenting out this line: /etc/redis.conf
#bind 127.0.0.1
Given the nature of Redis, and its very high speeds, an attacker may brute force the password without many issues. That is why we recommend uncommenting the requirepass line and adding a complex password (or a complex passphrase, preferably): /etc/redis.conf
requirepass your_redis_master_password
Depending on your usage scenario, you may change the following line or not. For the purpose of this tutorial, we assume that no key deletion must occur. Uncomment this line and set it as follows: /etc/redis.conf
maxmemory-policy noeviction
Finally, we want to make the following changes, required for backing up data. Uncomment and/or set these lines as shown: /etc/redis.conf
appendonly yes appendfilename "appendonly.aof"
Save your changes.
Restart the Redis service to reload our configuration changes:
sudo systemctl restart redis.service
Now that we have the master server ready, let's move on to our slave machine. Step 3 — Configure Redis Slave
We need to make some changes that allow our slave server to connect to our master instance:
Open /etc/redis.conf with your favorite text editor:
sudo vi /etc/redis.conf
Edit the following lines; some settings will be similar to the master's.
Make the server accessible to anyone on the web by commenting out this line: /etc/redis.conf
#bind 127.0.0.1
The slave server needs a password as well so we can give it commands (such as INFO). Uncomment this line and set a server password: /etc/redis.conf
requirepass your_redis_slave_password
Uncomment this line and indicate the IP address where the master server can be reached, followed by the port set on that machine. By default, the port is 6379: /etc/redis.conf
slaveof your_redis_master_ip 6379
Uncomment the masterauth line and provide the password/passphrase you set up earlier on the master server: /etc/redis.conf
masterauth your_redis_master_password
Now save these changes, and exit the file. Next, restart the service like we did on our master server:
sudo systemctl restart redis.service
This will reinitialize Redis and load our modified files.
Connect to Redis:
redis-cli -h 127.0.0.1 -p 6379
Authorize with the slave server's password:
AUTH your_redis_slave_password
At this point we are running a functional master-slave Redis cluster, with both machines properly configured. Step 4 — Verify the Master-Slave Replication
Testing our setup will allow us to better understand the behavior of our Redis Droplets, once we want to start scripting failover behavior. What we want to do now is make sure that our configuration is working correctly, and our master is talking with the slave Redis instances.
First, we connect to Redis via our terminal, on the master server:
First connect to the local instance, running by default on port 6379. In case you've changed the port, modify the command accordingly.
redis-cli -h 127.0.0.1 -p 6379
Now authenticate with Redis with the password you set when configuring the master:
AUTH your_redis_master_password
And you should get an OK as a response. Now, you only have to run:
INFO
You will see everything you need to know about the master Redis server. We are especially interested in the #Replication section, which should look like the following output:
Output . . .
Replication
role:master connected_slaves:1 slave0:ip=111.111.111.222,port=6379,state=online,offset=407,lag=1 master_repl_offset:407 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:2 repl_backlog_histlen:406
. . .
Notice the connected_slaves:1 line, which indicates our other instance is talking with the master Droplet. You can also see that we get the slave IP address, along with port, state, and other info.
Let's now take a look at the #Replication section on our slave machine. The process is the same as for our master server. Log in to the Redis instance, issue the INFO command, and view the output:
Output . . .
Replication
role:slave master_host:111.111.111.111 master_port:6379 master_link_status:up master_last_io_seconds_ago:3 master_sync_in_progress:0 slave_repl_offset:1401 slave_priority:100 slave_read_only:1 connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
. . .
We can see that this machine has the role of slave, is communicating with the master Redis server, and has no slaves of its own. Step 5 — Switch to the Slave
Building this architecture means that we also want failures to be handled in such a way that we ensure data integrity and as little downtime as possible for our application. Any slave can be promoted to be a master. First, let's test switching manually.
On a slave machine, we should connect to the Redis instance:
redis-cli -h 127.0.0.1 -p 6379
Now authenticate with Redis with the password you set when configuring the slave
AUTH your_redis_slave_password
Turn off slave behavior:
SLAVEOF NO ONE
The response should be OK. Now type:
INFO
Look for the # Replication section to find the following output:
Output . . .
Replication
role:master connected_slaves:0 master_repl_offset:1737 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
. . .
As we expected, the slave has turned into a master, and is now ready to accept connections from other machines (if any). We can use it as a temporary backup while we debug our main master server.
If you have multiple slaves that depended on the initial master, they all have to be pointed towards the newly promoted master.
This can be scripted easily, with the following steps needing to be implemented once a failure is detected:
From the application, send all requests for Redis to a slave machine
On that slave, execute the SLAVEOF NO ONE command. Starting with Redis version 1.0.0, this command tells the slave to stop replicating data, and start acting as a master server
On all remaining slaves (if any), running SLAVEOF hostname port will instruct them to stop replicating from the old master, discard the now deprecated data completely, and start replicating from the new master. Make sure to replace hostname and port with the correct values, from your newly promoted master
After analyzing the issue, you may return to having your initial server as master, if your particular setup requires it
There are many ways of accomplishing the steps explained above. However, it is up to you to implement an adequate solution for your environment, and make sure to test it thoroughly before any actual failures occur. Step 6 — Reconnect to the Master
Let's reconnect to the original master server. On the slave server, log in to Redis and execute the following:
SLAVEOF your_redis_master_ip 6379
If you run the INFO command again, you should see we have returned to the original setup.
RabbitMQ
1.http://www.unixmen.com/install-erlang-elixir-centos-7/ 2.https://www.unixmen.com/install-rabbitmq-server-centos-7/
yum install erlang rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc yum install rabbitmq-server Port Access
SELinux and similar mechanisms may prevent RabbitMQ from binding to a port. When that happens, RabbitMQ will fail to start. Make sure the following ports can be opened: 防火墙添加端口: 4369 (epmd), 25672 (Erlang distribution) 5672, 5671 (AMQP 0-9-1 without and with TLS) 15672 (if management plugin is enabled) 61613, 61614 (if STOMP is enabled) 1883, 8883 (if MQTT is enabled) then, run the following command to allow SELinux to enable RabbitMQ service:
setsebool -P nis_enabled 1
systemctl start rabbitmq-server
systemctl enable rabbitmq-server
Now, check the status of RabbitMQ server using the following commands:
rabbitmqctl status
Access RabbitMQ management console
RabbitMQ management console will allow you to monitor the server processes via a web browser.
To enable the RabbitMQ management console, run the following command:
rabbitmq-plugins enable rabbitmq_management
chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/
Now. open your web browser and navigate to the following URL to access your RabbitMQ server management console.
http://ip-address:15672/
The default user name and password of RabbitMQ Management console is ‘guest’ and ‘guest’ .
However, you can create a new admin user if you want.
To do so, run:
rabbitmqctl add_user mqadmin mqadmin
rabbitmqctl set_user_tags mqadmin administrator
rabbitmqctl set_permissions -p / mqadmin "." "." ".*"
Enter the username and password to access RabbitMQ web console:
zookeeper
http://wangshirufeng.iteye.com/blog/2279578 (服务) http://linuxsogood.org/1478.html http://www.centoscn.com/image-text/config/2015/0827/6063.html wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz $ mv conf/zoo_sample.cfg conf/zoo.cfg(将zookeeper/conf/目录下zoo_sample.cfg 更名为 zoo.cfg) $ ./bin/zkServer.sh start
gradle
https://gradle.org/gradle-download/
curl -s https://get.sdkman.io | bash
sdk install gradle 3.2.1
查看可用的sdk 版本
$ sdk list gradle
指定临时版本:仅当前终端生效
$ sdk user gradle 3.2.1
显示当前使用的版本:
$ sdk current gradle
scala
https://www.scala-lang.org/documentation/getting-started.html
Unix $SCALA_HOME /usr/local/share/scala $PATH $PATH:$SCALA_HOME/bin
kafka
https://mos.meituan.com/library/32/how-to-install-kafka-on-centos7/
功能验证
1.启动Zookeeper
使用安装包中的脚本启动单节点Zookeeper 实例:
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties [2015-10-26 04:26:59,585] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)....
2.启动Kafka 服务
使用kafka-server-start.sh 启动kafka 服务:
bin/kafka-server-start.sh config/server.properties [2015-10-26 04:28:56,115] INFO Verifying properties (kafka.utils.VerifiableProperties) [2015-10-26 04:28:56,141] INFO Property broker.id is overridden to 0 (kafka.utils.VerifiableProperties)
3.创建topic
使用kafka-topics.sh 创建单分区单副本的topic test:
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test 查看topic:
bin/kafka-topics.sh --list --zookeeper localhost:2181 test
4.产生消息
使用kafka-console-producer.sh 发送消息:
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test Hello world! Hello Kafka!
5.消费消息
使用kafka-console-consumer.sh 接收消息并在终端打印:
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning Hello world! Hello Kafka!
单机多broker 集群配置
利用单节点部署多个broker。 不同的broker 设置不同的 id,监听端口及日志目录。 例如:
cp config/server.properties config/server-1.properties
编辑配置:
config/server-1.properties: broker.id=1 port=9093 log.dir=/tmp/kafka-logs-1
启动Kafka服务:
bin/kafka-server-start.sh config/server-1.properties &
启动Kafka服务:
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
增加服务:
cat > /etc/systemd/system/kafka.service <<EOF
[Service]
ExecStart=/usr/local/kibana/bin/kibana
[Install]
WantedBy=multi-user.target
EOF