#1. 查看是否安装epel,没安装先安装
yum install epel-release
#2.更新文件库
yum -y update
#3. 各种依赖库
yum install -y gcc openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel libcurl-devel libevent libevent-devel memcached libmemcached libmemcached-devel
#4. 安装git
yum install -y git
#5. 安装nginx
yum install -y nginx
#6. 安装wget
yum -y install wget
#7.安装pip
yum -y install python-pip
#8. 安装虚拟环境包
pip install virtualenv virtualenvwrapper
echo 'source /usr/bin/virtualenvwrapper.sh' >> ~/.bashrc
source ~/.bashrc
#9. 下载编译安装python3.6.4 及其 创建虚拟环境
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
tar -zxvf Python-3.6.4.tgz
cd Python-3.6.4
./configure && make && make install
cd /root/.virtualenvs
python3 -m venv py36
#10. 安装supervisor,需退出虚拟环境
su root
yum install -y supervisor
mkdir -p /var/www/etc/supervisor.d
在里面添加服务所需配置文件 flower.conf, tasks.conf, webservices.conf等
vi /etc/supervisord.conf 最后加入 files = /var/www/etc/supervisor.d/*.conf
systemctl enable supervisord # 开机自启动
systemctl start supervisord # 启动supervisord服务
systemctl status supervisord # 查看supervisord服务状态
supervisorctl reload # 来重新加载配置文件,否则不会生效
#11. 安装mysql(开机自启动)(mysql Ver 14.14 Distrib 5.7.23, for Linux (x86_64) using EditLine wrapper)
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install -y mysql-server
# 启动mysql
systemctl start mysqld (若失败,查看/etc/my.cnf文件里面的data目录是哪个,把里面的文件删除。)
# 加入开机项
systemctl enable mysqld.service
# 设置root密码
grep 'temporary password' /var/log/mysqld.log
mysql -u root -p
set password=password("123456");
# 创建用户mysql,设置密码,权限
CREATE USER 'mysql'@'%' IDENTIFIED BY '123456;
GRANT ALL ON *.* TO 'mysql'@'%' identified by "123456";
#12. mongodb
安装:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.5.tgz # 下载
tar -zxvf mongodb-linux-x86_64-4.0.5.tgz # 解压
mv mongodb-linux-x86_64-4.0.5/ /usr/local/mongodb # 将解压包拷贝到指定目录
加入环境变量,可以在任意目录运行mongod
(1)vi /etc/profile
(2)最后写入
export MONGODBPATH=/usr/local/mongodb
export PATH=$PATH:$MONGODBPATH/bin
(3)source /etc/profile
创建配置文件
touch /usr/local/mongodb/bin/mongodb.conf
写入配置
dbpath=/usr/local/mongodb/data/db/ # 数据存储位置,无则需创建
logpath=/var/log/mongodb.log # 日志文件
logappend=true
port=27017
fork=true
auth=true
加入开机自启动:
(1)创建服务文件:
sudo vim /usr/lib/systemd/system/mongodb.service
(2)写入以下内容:
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/bin/mongodb.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
(3)重载系统服务, 启动
systemctl daemon-reload
systemctl start mongodb.service
#12. 安装rabbitmq(开机自启动)
安装erlang:
rpm -Uvh http://www.rabbitmq.com/releases/erlang/erlang-18.1-1.el7.centos.x86_64.rpm
# 安装rabbitmq
rpm -Uvh http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.6/rabbitmq-server-3.5.6-1.noarch.rpm
# 启动
service rabbitmq-server start
# 开机启动
chkconfig rabbitmq-server on
#13. 安装redis(开机自启动)
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
tar xzf redis-4.0.2.tar.gz
cd redis-4.0.2
make && make install
# 开机启动 https://blog.csdn.net/u012219045/article/details/85091774
# 启动redis
sudo systemctl start redis
# 后台启动方式
redis-server &
#14. 启动 memcached
安装: yum -y install memcached
启动: memcached -u root -d
连接: telnet 127.0.0.1 11211
列举出所有keys: stats items
加入开机项: systemctl enable memcached.service
#16. 安装代码所依赖的库
pip3 install -r requirement.txt
# 安装pycurl有个问题注意点,否则会报错(libcurl link-time ssl backend (nss) is different from compile-time ssl backend)
pip uninstall pycurl (若已经安装先卸载)
vi ~/.bash_profile
export PYCURL_SSL_LIBRARY=nss
pip install pycurl==7.43.0.1
# kombu (4.1.0)
# celery (4.0.2)
#17. 安装wkhtmltopdf, 拷贝中文字体
https://blog.csdn.net/u012219045/article/details/81365321
#20. nginx配置
# vi /etc/nginx/nginx.conf
# cd /etc/nginx/conf.d/
# 注意:nginx 403问题:
(1)将nginx.config的user改为和启动用户一致
(2)缺少index.html或者index.php文件
(3)如果nginx没有web目录的操作权限,也会出现403错误。
(4)SELinux设置为开启状态(enabled)的原因。 vi /etc/selinux/config 将SELINUX=enforcing 修改为 SELINUX=disabled 状态,reboot.
#21. 停止防火墙,开放80,443,22,21,3306等端口
# 注意:开启防火墙后,会自动把iptables停止。2个用其中一个就行,用iptables就关闭防火墙
service firewalld stop
yum install -y iptables iptables-services
touch iptables.sh
# #!/bin/sh
# iptables -P INPUT ACCEPT
# iptables -F
# iptables -X
# iptables -Z
# iptables -A INPUT -i lo -j ACCEPT
# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# iptables -A INPUT -p tcp --dport 21 -j ACCEPT
# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# iptables -A INPUT -p tcp --dport 2209 -j ACCEPT
# iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
# iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -P INPUT DROP
# iptables -P OUTPUT ACCEPT
# iptables -P FORWARD DROP
# service iptables save
# systemctl restart iptables.service
sh iptables.sh
#24. supervisorctl 启动服务
#25. memcache, redis, rabbitmq, mysql, supervisor, ntp, crond, nginx, iptables 加入开机自启动