Oracle 云主机默认镜像ubuntu 18.04的坑

开了一台甲骨文的San Jose 数据中心的Cloud VM,默认支持的系统中没有debian,因此退而求其次选择了ubuntu 18.04 minimum.

按照习惯,把SSH端口从22改成了一个其他的端口,但是确发现SSH始终都连不上了.  检查了这个VM的security list,所有的端口都打开了,没有问题,看来问题只能出在ubuntu的默认防火墙上了.

默认的ubuntu 18.04的防火墙是iptables, 默认没有安装ufw,而且oracle 官方也不推荐使用ufw(这是后来才知道的)

可是按照ubuntu/debian的默认安装,防火墙iptables虽然是默认开启的,但是里面没有任何的规则. google了半天才发现原来是Oracle给他的默认的linux 的OS 都写入了默认的规则,路径在/etc/iptables/rules.v4 和rules.v6.

把rules.v4的规则里的两条reject 规则给他comment out,就可以了.

#-A INPUT -j REJECT --reject-with icmp-host-prohibited
#-A FORWARD -j REJECT --reject-with icmp-host-prohibited

 

Discuz开发 discuz 论坛注册,登录流程整理

discuz 论坛 用户注册流程
第一步:
/source/class/class_member.php: on_register注册入口
L602 左右
if(!$activation) {//不为空,说明用户已经注册过
//将用户注册到用户中心,调用第二步uc_user_register方法
$uid = uc_user_register(addslashes($username), $password, $email, $questionid, $answer, $_G[‘clientip’]);

第二步:
/uc_client/client.php: uc_user_register 调用将用户注册到用户中心的方法,调用第三步的onregister方法
第三步:
/uc_client/control/user.php: onregister 将用户注册到用中心,调用第四步add_user方法
第四步:
/uc_client/model/user.php:add_user 将用户注册到ucenter返回用户id
第五步:
/source/class/class_member.php:
L685行 左右,会把用户信息写到common_member表。注册结束
C::t(‘common_member’)->insert($uid, $username, $password, $email, $_G[‘clientip’], $groupinfo[‘groupid’], $init_arr);

discuz 论坛 登陆流程
第一步:
/source/class/class_member.php: on_login 登陆入口
87行左右,调用userlogin方法如下:
$result = userlogin($_GET[‘username’], $_GET[‘password’], $_GET[‘questionid’], $_GET[‘answer’], $this->setting[‘autoidselect’] ? ‘auto’ : $_GET[‘loginfield’], $_G[‘clientip’]);
第二步:
/source/function/function_member.php: logincheck
72行左右 调用 logincheck,如下:
if(!($_G[‘member_loginperm’] = logincheck($_GET[‘username’]))) {
showmessage(‘login_strike’);
}
第三步:
/source/function/function_member.php: userlogin 用户登陆查询相关表
第29行-40行左右会用调用uc_user_login方法
if($isuid == 3) {
if(!strcmp(dintval($username), $username) && getglobal(‘setting/uidlogin’)) {
$return[‘ucresult’] = uc_user_login($username, $password, 1, 1, $questionid, $answer, $ip);// uc_client/client.php
} elseif(isemail($username)) {
$return[‘ucresult’] = uc_user_login($username, $password, 2, 1, $questionid, $answer, $ip);// uc_client/client.php
}
if($return[‘ucresult’][0] <= 0 && $return[‘ucresult’][0] != -3) {
$return[‘ucresult’] = uc_user_login(addslashes($username), $password, 0, 1, $questionid, $answer, $ip);
}
} else {
$return[‘ucresult’] = uc_user_login(addslashes($username), $password, $isuid, 1, $questionid, $answer, $ip);
}

/uc_client/client.php: 包含uc_开头的全部方法,例uc_user_login
/uc_client/control/user.php: onlogin 根据条件判断登陆,114-120 判断查询条件查询出ucenter用户信息
/uc_client/model/user.php 包含有get_user_by_uid,get_user_by_username 等方法 第50行左右查询common_member表,如下:
$member = getuserbyuid($return[‘ucresult’][‘uid’], 1);

回到/source/class/class_member.php文件on_login方法

第95-106 行左右会根据条件$result[‘status’]==-1 ,写common_member表,并查询出写入信息
C::t(‘common_member’)->insert($uid, $result[‘ucresult’][‘username’], md5(random(10)), $result[‘ucresult’][’email’], $_G[‘clientip’], $groupid, $init_arr);
$result[‘member’] = getuserbyuid($uid);

————————————————————————————-
ps:以上所有方法都会先执行
/source/class/discuz/discuz_application.php: _init_user
所以如果要自己写checklogin 可以考虑从_init_user 方法入手

如果与自己的平台做bbs的打通。
注册可以考虑在第4步做操作,调用自己平台的注册接口。注册用户,并将用户id返回。写入到ucenter
/uc_client/model/user.php:add_user 方法内

登陆打通可以考虑在 第三步调用 uc_user_login 方法前,
1.调用自己平台接口查询用户相关信息
2.查询ucenter中用户是否存在
3.如果不存在insert一条数据
4.common_member可以写也可以不写 ,如此时不写 $result[‘status’]==-1 会在class_member 95-106 行左右写入

如果在自己平台处于登陆状态,在discuz 也为登陆状态,则可以考虑从_init_user 方法入手。做登录判断

Discuz 3.2, 3.3, 3.4 直接利用SQL创建新用户

我们的网站要和Discuz整合到一起,有个新用户同步的需求,网络上很多的做法是用 UCenter的接口来做,反正最后都是插入SQL,笔者使用了直接操作数据库的方式,把操作的表和SQL整理了下,后面如果有时间做个SSO就省事了

版本:dz 3.2版本 ucenter1.6版本
目标:插入普通用户,最小可用就行了,可以登录

SQL记录:

注意:表名称前缀根据配置可能不同, 一共有8张表

SELECT *FROM pre_ucenter_members;
-- UCenter用户数据表 uid, username, password, email, regip(默认写一个值), regdate(时间戳), salt(随机6位字母数字)

SELECT *FROM pre_ucenter_memberfields;
-- UCenter用户扩展信息数据表 插入 uid

SELECT *FROM pre_common_member;
-- 主用户表 插入的字段 email, username, password, emailstatus, regdate(时间戳)
-- 得到uid再插入其它表

SELECT *FROM pre_common_member_count;
-- 用户数据统计 各种积分,动态等 插入 uid

SELECT *FROM pre_common_member_field_forum;
-- 用户论坛设置数据表 插入 uid

SELECT *FROM pre_common_member_field_home;
-- 用户家园设置数据表 插入 uid

SELECT *FROM pre_common_member_profile;
-- 用户个人资料数据表 插入 uid

SELECT *FROM pre_common_member_status;
-- 用户状态数据表 插入 uid


-- 下面是插入一个普通用户的测试, 这里根据id自增,自己算出了uid,便于sql书写 
-- lzz, 邮箱 [email protected], 密码 xyz2541 
-- 需要计算的密码 pre_common_member 密码为 md5(password) 2cf5c897f58ca21cac9bec93f46f6f53
-- pre_ucenter_members salt yyy111 密码为 md5(md5(password)+salt) 4fab791987738fce5f11504a0fe2a342
-- MYSQL mode 设置的比较严格,所以很多默认值要自己加上。。

INSERT INTO pre_ucenter_members SET uid=7, username='lzz', `password`='4fab791987738fce5f11504a0fe2a342', email='[email protected]', regip='127.0.0.1', regdate=UNIX_TIMESTAMP(), salt='yyy111';

INSERT INTO pre_ucenter_memberfields SET uid=7, blacklist='';

INSERT INTO pre_common_member SET uid=7, username='lzz', `password`='2cf5c897f58ca21cac9bec93f46f6f53', email='[email protected]', emailstatus=1, regdate=UNIX_TIMESTAMP();

INSERT INTO pre_common_member_count SET uid=7;

INSERT INTO pre_common_member_field_forum SET uid=7, `medals`='', `sightml`='', `groupterms`='', `groups`='';

INSERT INTO pre_common_member_field_home SET uid=7, `spacecss`='', `blockposition`='', 
`recentnote`='', `spacenote`='', `privacy`='', `feedfriend`='', `acceptemail`='', `magicgift`='', `stickblogs`='';

INSERT INTO pre_common_member_profile SET uid=7, `bio`='', `interest`='', `field1`='', `field2`='',
`field3`='', `field4`='', `field5`='', `field6`='', `field7`='', `field8`='';

INSERT INTO pre_common_member_status SET uid=7;

在Discuz的数据库中插入到数据库之后,web端就能登录了

Ucenter中的用户批量导入到discuz中的办法

这个代码是搜索到的,主要看一下需要在数据库里更新哪些表格.

将下面的代码复制到一个php中,并在浏览器中输入地址执行:

<?php
$dbserver =’localhost’; //此处改成数据库服务器地址
$dbuser =’root’;//此处写数据库用户名
$dbpwd =’1234′;//数据库密码
$dbname =’disucz’;//数据库名称
$charset =’gbk’;//此处写字符集gbk或者utf8
$uc_pre =’pre_ucenter_’;//UC表前缀
$dx_pre =’pre_’;//Discuz! X2表前缀
//此行开始向下不要改动
set_time_limit(0); //0为无限制
$connect=mysql_connect($dbserver,$dbuser,$dbpwd) or die(“无法连接数据库”);
@mysql_select_db($dbname,$connect);
mysql_query(“set names $charset”);
$query = mysql_query(“SELECT * FROM `{$uc_pre}members` WHERE `uid` not in(select `uid` from `{$dx_pre}common_member`) “,$connect);
while($user = mysql_fetch_array($query)) {
$password=$user[password];
mysql_query(” replace INTO `{$dx_pre}common_member` (uid,username,password,adminid,groupid,regdate,email) VALUES (‘$user[uid]’, ‘$user[username]’, ‘$password’,’0′,’10’,’$user[regdate]’,’$user[email]’) “);
mysql_query(” replace INTO `{$dx_pre}common_member_field_forum` (uid) VALUES (‘$user[uid]’)”);
mysql_query(” replace INTO `{$dx_pre}common_member_field_home` (uid) VALUES (‘$user[uid]’)”);
mysql_query(” replace INTO `{$dx_pre}common_member_count` (uid) VALUES (‘$user[uid]’)”);
mysql_query(” replace INTO `{$dx_pre}common_member_profile` (uid) VALUES (‘$user[uid]’)”);
mysql_query(” replace INTO `{$dx_pre}common_member_status` (uid) VALUES (‘$user[uid]’)”);
}
echo “已从UC批量导入激活成功”;
?>

注释: 连接到数据库后,PHP会比对UC和DZ用户表的数据,发现不存在于DZ但是存在于UC的用户,就会把用户导入到DZ,但是这一注册不会设置其他内容,比如用户填写的详细信息,由于以前是存储在DZ数据库中,所以还是丢失了

这样子用户已经全部导入,用户数也恢复了正常

下一步,将用户的邮箱验证全部设置为已验证

数据库执行:

update pre_common_menber set emailstatus="1";

注释:这是更新数据库中emailstatus字段,1为验证 pre记得改为你的论坛的前缀

 

 

GV和环聊该使用哪个?

Google Voice 有两个app,一个是google voice,一个是hangouts, 这两个app相比较来说肯定是hangouts好用很多

但是这个只是在苹果手机上而言, 在苹果手机上你可以使用hangouts来接发短信和拨收电话,确实很方便

但是在安卓手机上,hangouts 只能接受和发短信,无法拨打电话,需要一个叫做环聊拨号器的app,也是google开发的,但是

环聊拨号器这个app 早在2015年就停止更新了

因此在苹果手机上使用hangouts,在安卓手机上使用GV apps 是最好的选择

Centos 7 通过openresty repo 安装openresty 解析

通过openresty repo 安装的文档可以看这里:

https://openresty.org/en/linux-packages.html

目前用yum安装的过程中,安装的组件版本如下:

Installing:
openresty x86_64 1.17.8.2-1.el7 openresty 1.1 M
Installing for dependencies:
openresty-openssl111 x86_64 1.1.1g-3.el7 openresty 1.6 M
openresty-pcre x86_64 8.44-1.el7 openresty 164 k
openresty-zlib x86_64 1.2.11-3.el7.centos openresty 54 k

安装openresty resty的话,版本如下:

openresty-resty-1.17.8.2-1.el7.noarch

openresty 的bin 安装路径为:

/usr/bin/openresty

查看一下使用repo安装的openresty的详细配置:

[root@centos ~]# openresty -V
nginx version: openresty/1.17.8.2
built by gcc 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
built with OpenSSL 1.1.1g 21 Apr 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.17 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../ngx_stream_lua-0.0.8 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' --with-cc='ccache gcc -fdiagnostics-color=always' --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-stream_ssl_preread_module --with-http_ssl_module

可以看到基本上配置的非常全面的,非常好了

看一下本机的openssl version:

[root@centos ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017

查看一下openresty service配置:

[Unit]
Description=The OpenResty Application Platform
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Openresty 默认的nginx conf 位于:

/usr/local/openresty/nginx/conf/nginx.conf

配置为:

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

Zabbix Agent的安装和使用

最近需要在服务器集群上监控服务器们的CPU和RAM的使用情况,zabbix 主服务器在US, agent 安装在监控的服务器上.

总的来说其实很简单,主要就是两个步骤:

  1. 安装zabbix agent 组件并且设置好conf文件
  2. 防火墙打开10050端口或者直接whitelist zabbix主服务器的IP

 

下面是详细的步骤:

1 安装组件

4.4 for centos and debian

Centos 7: 

rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm

yum install zabbix-agent

Centos 8:

rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/8/x86_64/zabbix-release-4.4-1.el8.noarch.rpm

yum install zabbix-agent

Debian 9:

# wget https://repo.zabbix.com/zabbix/4.4/debian/pool/main/z/zabbix-release/zabbix-release_4.4-1+stretch_all.deb
# dpkg -i zabbix-release_4.4-1+stretch_all.deb
# apt update

#apt install zabbix-agent

Debian 10:

# wget https://repo.zabbix.com/zabbix/4.4/debian/pool/main/z/zabbix-release/zabbix-release_4.4-1+buster_all.deb
# dpkg -i zabbix-release_4.4-1+buster_all.deb
# apt update

#apt install zabbix-agent

zabbix 5.0 LTS for debian 9

# wget https://repo.zabbix.com/zabbix/5.0/debian/pool/main/z/zabbix-release/zabbix-release_5.0-1+stretch_all.deb
# dpkg -i zabbix-release_5.0-1+stretch_all.deb
# apt update

# apt install zabbix-agent

zabbix 5.0 LTS for centos 7

# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

# yum install zabbix-agent

2 修改配置文件

无论centos 还是debian,都是在/etc/zabbix/zabbix-agentd.conf

agent 可以以两种模式运行: passive 和 active,我们一般使用passive 模式就可以,也最简单,只需要修改

Passive checks related下面的Server IP就可以

默认的是Server=127.0.0.1, 把127.0.0.1改成你的zabbix 主服务器的IP就可以了

3 防火墙打开10050 端口或者直接whitelist 你的zabbix主服务器的IP就可以了

Priceonomics:美国买房最实惠和最不实惠的城市排行榜

一直有在美国买房的打算,刚好看到这个统计,就转过来

美国最实惠的地方是俄亥俄州的扬斯敦,紧随其后的是密西西比州的杰克逊。在这两个地方,家庭收入中位数都高于一套房子的购买价格。最实惠城市排行榜上的每个城市都位于南部或中西部。在美国的609个地方中只有50个的负担能力得分超过36%。美国的绝大多数地方的房价都很难负担得起。

接下来,我们来看看美国最负担不起的住房市场。以下图表显示了地方收入对购房影响不大的地方:

美国最负担不起的地方是加利福尼亚州的纽波特海滩,紧随其后的是加利福尼亚州的圣莫尼卡。在这些地方,典型的年收入仅占房屋购买价格的5.3%。事实上,在最负担不起的城市排行榜25名中有24个位于加利福尼亚州。

对于购房者来说,美国最实惠的州是密西西比州,紧随其后的是俄亥俄州和俄克拉何马州。最负担得起的12个州中的每一个都在南部和中西部。最负担不起的州是夏威夷、华盛顿特区和加利福尼亚州。最负担不起的地方都在这个国家的西部和东部。

在美国最大的50个市场中,密歇根州的底特律是最实惠的,因为一个家庭的工资与房屋购买价格的比率为83.4%。排名前5位的城市都在南部或中西部。旧金山是美国最负担不起的大城市,紧随其后的是洛杉矶和奥克兰。排名前十的城市中有6个位于加利福尼亚州,纽约、火奴鲁鲁、波士顿和迈阿密也跻身最负担不起的主要城市之列。