重置了系统后,干干净净的一台centos6 系统,用了快3年的服务器一切要从头开始,有点蓝瘦,头快秃了
进入新的全新系统,第一步先装环境。
由于系统是centos6,在2020年12月开始,centos6就不再被官方更新了,所以yum等工具会导致如下报错:
所以需要执行以下代码修复:
sed -i "s|enabled=1|enabled=0|g" /etc/yum/pluginconf.d/fastestmirror.conf
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://www.xmpan.com/Centos-6-Vault-Aliyun.repo
yum clean all
yum makecache
yum -y install wget zip unzip lrzsz gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel pcre-devel gcc-devel python-devel
centos安装python3环境可以看我之前写的这篇
可以看到,一般linux自带python是2.6版的,所以需要装一个3.6的,并更换yum和pip依赖
新建存放python36安装包的文件夹
mkdir -p /usr/local/soft/python36
cd /usr/local/soft/python36
下载python36安装包
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
解压
tar -zxvf Python-3.6.0.tgz
安装到 /usr/local/python36
mkdir -p /usr/local/python36
cd Python-3.6.0
./configure --prefix=/usr/local/python36
make && make install
mv /usr/bin/python /usr/bin/python-2.6.6
ln -s /usr/local/python36/bin/python3.6 /usr/bin/python
由于yum底层使用的是python2.6,所以需要将yum使用的python保持原有的2.6版本
vim /usr/bin/yum
软链接
ln -s /usr/local/python36/bin/pip3 /usr/bin/pip
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python环境搞定
centos安装mysql可以参考这篇文章
先检测系统上是否自带mysql
yum list installed | grep mysql
可以看到有自带的mysql 5.1,但是之前使用的是5.7,这次重新安装环境所以也决定用新版的mysql8,所以需要先卸载再重装
yum -y remove mysql-libs.x86_64
新建mysql安装包路径
mkdir -p /usr/local/soft/mysql
cd /usr/local/soft/mysql
下载安装包
wget https://dev.mysql.com/get/mysql80-community-release-el6-3.noarch.rpm
安装
rpm -ivh mysql80-community-release-el6-3.noarch.rpm
yum -y install mysql-server
mysqladmin -V
yum -y install mysql-devel
mysql安装完后,开始进行一系列的配置
先启动服务
service mysqld start
service mysqld status
cat /var/log/mysqld.log
mysql -uroot -p
alter user user() identified by 'password';
use mysql;
update user set host = '%' where user ='root';
flush privileges;
select user,host from user;
退出
quit;
开启远程登录
service iptables stop
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/rc.d/init.d/iptables restart
但是远程连接出现了报错:
原来是因为mysql8以后更改了加密规则
所以需要
再进入到mysql中更新密码成之前的加密规则
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
接下来开始导入之前备份好的mysql数据
先建文件夹放数据
mkdir -p /usr/local/website/mysql_data
通过ftp把之前备份好的数据放进去,压缩包都280M,慢慢等…
解压数据
unzip mysite_sql.zip
导入到mysql
mysql -uroot -p mysite < dump.sql
速度还是非常快了
最后配置sql_mode,删除ONLY_FULL_GROUP_BY模式
set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
mysql的配置就搞完了!
yum install git
git config --global user.name username
git config --global user.email email@mail.com
生成ssh密钥
ssh-keygen -t rsa -C "你的邮箱"
查看ssh公钥
cat /root/.ssh/id_rsa.pub
然后登录git网页添加ssh keys
接下来克隆我项目的代码到服务器上
注意,如果git项目是私有的,在克隆的项目地址需写成这样的格式
git clone https://git用户名:git密码@github.com/git用户名/git项目.git
mkdir /usr/local/mongodb
tar -zxvf /usr/local/soft/mongo/mongodb-linux-x86_64-4.0.18.tgz -C /usr/local/mongodb
cd /usr/local/mongodb/mongodb-linux-x86_64-4.0.18
mkdir datas
mkdir logs
touch logs/mongodb.log
vi mongodb.conf
#端口号
port=27017
#db目录
dbpath=/usr/local/mongodb/mongodb-linux-x86_64-4.0.18/datas
#日志目录
logpath=/usr/local/mongodb/mongodb-linux-x86_64-4.0.18/logs/mongodb.log
#日志输出
logappend=true
#后台
fork=true
#允许远程ip连接
bind_ip=0.0.0.0
#开启验证
auth=true
导入数据前需先把auth关掉
/usr/local/mongodb/mongodb-linux-x86_64-4.0.18/bin/mongoimport -h localhost -d recommend -c vod_recommend --file mongo_recommend.json
进入mongo
bin/mongo
use admin
db.createUser(
{
user: "username",
pwd: "password",
roles: [ {
role: "root", db: "admin" } ]
}
)
查看用户状态
show users
添加启动和关闭脚本
vim start-mongo.sh
#! /bin/bash
clear
/usr/local/mongodb/mongodb-linux-x86_64-4.0.18/bin/mongod -f /usr/local/mongodb/mongodb-linux-x86_64-4.0.18/conf/mongodb.conf
echo "start mongo..."
ps -ef | grep momgodb
vim stop-mongo.sh
#! /bin/bash
clear
/usr/local/mongodb/mongodb-linux-x86_64-4.0.18/bin/mongod --shutdown -f /usr/local/mongodb/mongodb-linux-x86_64-4.0.18/conf/mongodb.conf
echo "stop mongo..."
ps -ef | grep momgodb
更改权限
chmod +x start-mongo.sh
chmod +x stop-mongo.sh
pip 直接安装
pip install uwsgi
新建conf目录,存放uwsgi.ini、uwsgi.pid、uwsgi.status
mkdir -p /usr/local/uwsgi/conf
修改系统默认并发值
echo 8912 > /proc/sys/net/ipv4/tcp_max_syn_backlog
echo 262144 > /proc/sys/net/core/somaxconn
配置uwsgi.ini
[uwsgi]
chdir = /usr/local/website/mysite
module = mysite.wsgi:application
master = true
processes = 6
# add from here
harakiri = 60
harakiri-verbose = true
memory-report = true
reload-mercy = 15
reload-on-as= 1024
reload-on-rss=1024
socket-timeout=10
limit-post=4096
# end here 20200617
socket = 127.0.0.1:8008
vacuum = true
stats=/usr/local/uwsgi/conf/uwsgi.status
pidfile=/usr/local/uwsgi/conf/uwsgi.pid
enable-threads = true
daemonize=/var/log/uwsgi/uwsgi.log
log-maxsize = 5000000
listen=1024
启动uwsgi
uwsgi --ini /usr/local/uwsgi/conf/uwsgi.ini
采用的带防火墙的verynginx,还挺好用的,这里安利一下。
mkdir -p /usr/local/soft/verynginx
mkdir -p /var/log/nginx/
cd /usr/local/soft/verynginx
git clone https://github.com/alexazhou/VeryNginx.git
进入到目录开始安装
cd VeryNginx
python install.py install
配置uwsgi_params
mkdir -p /usr/local/nginx/conf
cd /usr/local/nginx/conf
vim uwsgi_params
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
准备启动服务
#启动服务
/opt/verynginx/openresty/nginx/sbin/nginx
#停止服务
/opt/verynginx/openresty/nginx/sbin/nginx -s stop
#重启服务
/opt/verynginx/openresty/nginx/sbin/nginx -s reload
配置文件修改redis.windows-service.conf:
修改绑定本地ip,不开放公网
bind 127.0.0.1
配置好redis后,cmd执行
redis-server.exe --service-install D:/software/redis/redis.windows-service.conf --loglevel verbose
redis-server --service-start
netstat -aon|findstr "9596"
停止服务
redis-server --service-stop
mkdir -p /usr/local/soft/redis/
mkdir -p /var/log/redis
cd /usr/local/soft/redis
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zxvf redis-3.2.8.tar.gz -C /usr/local/redis/
yum -y install tcl
cd /usr/local/redis/redis-3.2.8/
make MALLOC=libc
make test && make install
修改配置文件
vim redis.conf
bind 127.0.0.1
daemonize yes
pidfile /usr/local/redis/redis-3.2.8/redis_6379.pid
logfile "/var/log/redis/redis.log"
启动redis
bin/redis-server redis.conf