分类 我爱编程 下的文章

多主一从配置相关问题

主库配置请参考主从同步配置;
从库my.cnf相关配置:
[client]
#password = your_password
#port = 3306
#socket = /tmp/mysql.sock
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
[mysqld1]
port = 3306
socket = /tmp/mysql1.sock
datadir =/home/mysql/data1
log-error = /home/mysql/logs/mysql1_error.log
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 20
expire_logs_days = 10
default_storage_engine = InnoDB
innodb_data_home_dir =/home/mysql/data1
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir =/home/mysql/data1
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqld2]
port = 3307
socket =/tmp/mysql2.sock
datadir = /home/mysql/data2
log-error = /home/mysql/logs/mysql2_error.log
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 40
expire_logs_days = 10
default_storage_engine = InnoDB
innodb_data_home_dir = /home/mysql/data2
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /home/mysql/data2
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
初始化:
mysql1:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/home/mysql/data1/ --user=mysql
mysql2:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/home/mysql/data2/ --user=mysql
启动:
/usr/local/mysql/bin/mysqld_multi --config-file=/etc/my.cnf start 1-2
/usr/local/mysql/bin/mysqld_multi start 1-2
报错:找不到 my_print_defaults,
解决:ln -s /usr/local/mysql/bin/my_print_defaults /usr/bin/
启动后:
lsof -i:3306
lsof -i:3307
两个端口都有mysql在监听的话就表示启动成功了
分别访问mysql实例1,实例2
# /usr/local/mysql/bin/mysql -uroot -p123456 -P3306 -S /tmp/mysql1.sock
# /usr/local/mysql/bin/mysql -uroot -p123456 -P3307 -S /tmp/mysql2.sock
分别访问两个实例,删除多余用户,修改用户密码,修改用户的访问权限

无法使用hostname连接mysql

错误:InternalError: (1042, u"Can't get hostname for your address")
解决:
my.cnf:
[mysqld] skip-name-resolve

lxml安装出错

sudo apt-get install build-essential autoconf libtool pkg-config python-opengl python-imaging python-pyrex python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script libqt4-network libqt4-dbus python-qt4 python-qt4-gl libgle3 python-dev
sudo easy_install greenlet
sudo easy_install gevent

nginx+uwgis+django部署相关问题

1:出现无法安装pyhon3.5时手动更新源使用以下命令
(1)sudo add-apt-repository ppa:fkrull/deadsnakes
(2)sudo apt-get update
(3)sudo apt-get install python3.5
(4)sudo cp /usr/bin/python /usr/bin/python_bak,先备份
(5)sudo rm /usr/bin/python,删除
(6)sudo ln -s /usr/bin/python3.5 /usr/bin/python,默认设置成python3.5,重建软链接这样在终端中输入python默认就是 3.5版本了
2:当出现add-apt-repository command not found时:
sudo apt-get install software-properties-common python-software-properties
3:当安装uwgis出现gcc错误时:sudo apt-get install gcc
4:当安装uwgis出现 *** uWSGI compiling embedded plugins ***
[x86_64-linux-gnu-gcc -pthread] plugins/python/python_plugin.o
In file included from plugins/python/python_plugin.c:1:0:
plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
使用:
sudo apt-get install python3.5-dev(对应版本号选择)
5:前台启动uwgis,uwsgi --ini /home/django/search/search_uwsgi.ini &/usr/local/nginx/sbin/nginx
后台启动:uwsgi --ini /home/django/search/search_uwsgi.ini -d /home/log/uwsgi.log

Django+uwgis+nginx配置及http转发https

497错误重定向
nginx配置:
server {
               listen 80; #或监听ip:80
               listen 443 default ssl;#或监听ip:443
               server_name yunso.xyz
               charset UTF-8;
               access_log /var/log/nginx/search_access.log;
               error_log /var/log/nginx/search_error.log;
               error_page 497 https://yunso.xyz:443; #捕获497代码并跳转到https 无法跳转时使用监听ip:端口
               ssl on; #返回497代码
               ssl_certificate /usr/local/nginx/ssl/1_yunso.xyz_bundle.crt; #ssl的crt地址
               ssl_certificate_key /usr/local/nginx/ssl/2_yunso.xyz.key; #ssl的key地址
               client_max_body_size 75M;
               location / {
                              include uwsgi_params;
                              uwsgi_pass 127.0.0.1:8000;
                              uwsgi_read_timeout 2100s;
               }
               location /static {
                              expires 30d;
                              autoindex on;
                              add_header Cache-Control private;
                              alias /home/django/search/app/static/;
               }
}
注意问题:样式文件需要设置为本地路径,远程路径导致样式无法加载
497重写路由规则
server {
               listen 80;
               server_name my.domain.com;
               return 301 https://$server_name$request_uri; #新版本
               rewrite ^ https://$host$request_uri? permanent;#旧版本
}
server {
               listen 443 ssl;
               server_name my.domain.com;
               # add Strict-Transport-Security to prevent man in the middle attacks                      add_header Strict-Transport-Security "max-age=31536000"; [....]
}
错误497重定向
error_page 497 https://$host:$server_port$request_uri;